I'm reading a HTTP POST and the body of the HTTP request can be either JSON or XML. Now I've delegated the reading to a special utility class.
interface HttpUtils
{
BodyWrapper parseBody( HttpServletRequest req );
}
interface BodyWrapper
{
boolean isXML(); // 1
boolean isJSON(); // 2
String body(); // 3
}
- I hate the fact that BodyWrapper has methods (1 & 2) to identify its type. Perhaps I should use inheritance. If I do that, I will need to do an instanceof to find out what is being returned by HttpUtils.parseBody(..)
- Ideally I would also want the body() method to return either a JSONObject or an DOM node. How would I do that ?
Thanks