Hi ,
I was implementing Restful webservice using jersey 1.1.5 and able to get the result if the input is xml .But I am getting errors while using JSON as my input .I am doing this test using SOUPUI as my client.
I followed 2 ways to do this.
Scenario1.
1.Paasing my input in JSON format and in my service I have mentioned as
@Consumes( { MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
2.
private static String fromJsonToinputXml(String inputXml) throws Exception {
XMLSerializer serializer = new XMLSerializer();
JSON jsonO = JSONSerializer.toJSON(inputXml);
serializer.setRootName("searchCriteria");
serializer.setNamespace("subscription", "uri");
serializer.setTypeHintsEnabled(false);
String xml = serializer.write( jsonO );
System.out.println("===>" + xml);
return xml;
}
Here I am converting my JSON data which is passed as String and converted to JSON object and then Converting it to an XML .
Then I am unmarshal this xml to my JaxB object .Because I have to pass this jaxb object to my façade.
SearchRequestType searchReqType = (SearchRequestType) JaxbUtil
.unMarshallWithXMLString(SUBSCRIPT_CONTEXTPATH_REQ,
inputXml, SearchRequestType.class);
In this scenario after unmarshal the values in the object are getting null .
Scenarion2
==================
In this case
I am converting input json data to Json Object and then converting to java object like the below
private static Object fromJsontoJava(String inputXml) {
JSON json = JSONSerializer.toJSON(inputXml);
System.out.println("====>" + json.toString());
System.out.println("====>" + JSONSerializer.toJava(json));
return JSONSerializer.toJava(json);
}
After I got the JavaObject I am trying to typecase it to my JaxBObject where I was getting Classcastexception.
Could you please help me how can I overcome this issue.
I really appreciate your help.
Thanks and Regards,
Kamal.