Reputation: 545
I am sharing this for others working between Java clients and Web Services from .Net MVC4 and using RoboSpice and FasterXML Jackson frameworks. I could not find good information on stackoverflow on how to set up the JSON POJO class for proper object mapping for the POST result object. For POST operations the RESULT JSON comes back with the structure from the .Net web services:
{"ClassName":{"attribute_one":1,""attribute_two":1,"....}}
I could not figure out how to get the FastXml Jackson ObjectMapper readValue parsing to work. I got an empty result object after parsing with all the properties set to null or default values..., or invalid property name for the class name if I turned off the JsonIgnoreProperties.
The following POJO object definition finally worked for me. It has an outer class that matches the ClassName in the Result and then an inner static class for mapping the Single Result Object into a Java Class Object:
public class ClassNameOuter {
@JsonProperty("ClassName")
public ClassName _ClassName;
public ClassName get_ClassName() {
return _ClassName;
}
public void set_ClassName(ClassName _ClassName) {
this._ClassName = _ClassName;
}
@JsonIgnoreProperties(ignoreUnknown=true)
public static class ClassName {
@JsonProperty("attribute_one")
public long attribute_one;
@JsonProperty("attribute_two")
public long attribute_two;
For the experts out there on Jackson and Robospice....please share if there is a better way.
Upvotes: 2
Views: 705
Reputation: 38168
RoboSpice doesn't support yet parsing of XML using Jackson. It provides a module to parse XML using SimpleXMLSerializer but not jackson.
Can you indicate which classes of Jackson you used, I would add a module soon to RS.
Upvotes: 1