To get the XML data, Jackson was configured for @ResponseBody in spring MVC.
Just used when the heart is ecstatic, and finally do not have to resolve their own ...
But ......... .............. There is still a hole ...
Pit One: Capitalization problems
@JacksonXmlProperty (localname = "Apid")
Private Integer Apid;
Private Integer Getapid ()
{
return this. Apid
}
Placing annotations on the member variables will parse out two Apid fields, one is <apid></apid>, and the other is <apid><apid>
This is because Jackson's processing mechanism automatically gets the member variable name from the property method, but in Java, either the hump is named, or the first two letters are capitalized in order to get the property correctly with the Get method, so the member name obtained with Getapid is Apid, Was parsed out by Jackson. And because the member variables are annotated, they are also parsed. This resulted in an XML file generating two apid tags. The correct approach is to write the annotations to the Get method
Correct wording:
Private Integer Apid;
@JacksonXmlProperty (localname = "Apid")
Private Integer Getapid ()
{
return this. Apid
}
Pit II: Jackson Package list problem
This problem is extremely difficult to troubleshoot ... began to think that the problem of encapsulation .... (Spit It out, this outsourced project uses a lot of XML interaction, but it doesn't use WebService to parse the encapsulated XML in a fixed format ..... Change also thief difficult ... )...... And finally, it was Jackson's problem.
Private list<integer> APID;
@JacksonXmlProperty (localname = "APID")
@JacksonXmlElementWrapper (usewrapping = False)
Public list<integer> Getapid () {
return APID;
}
Start Apid This list has been packaged on two levels! The correct result should be <APID>111</APID>
But what I get is <APID><APID>111</APID></APID>.
The problem is in jacksonxmlelementwrapper ............... This value defaults to true if you do not specify ... ..... ..... ..... ..... ..... ..... ................. ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ...... .....
True when Jackson encapsulates XML directly with Xmlproperty's localname and sealed a layer ...
It would be nice to change this to false.
"Java" Jackson parsing the pit of XML