java - Jackson 2.8.9 @JsonPropertyOrder does not arrange field that is generated by @JsonTypeInfo when serializing XML -


i trying serialize , deserialize xml in following format:

<home>     <handle>300023</handle>     <command>login</command>     <content>         <user_id>300023</user_id>         <result>0</result>     </content> </home> 

and try map following classes:

@data @jacksonxmlrootelement(localname = "home") @jsonpropertyorder({"handle", "command", "content"}) public class home {      private long handle;      @jsontypeinfo(       use = jsontypeinfo.id.name,       include = jsontypeinfo.as.external_property,       visible = true,       property = "command")     @jsonsubtypes({         @jsonsubtypes.type(value = logincontent.class, name = "login")     })     private basecontent content; } 

and

@data @jsonpropertyorder({     "user_id",     "result"}) public class logincontent implements basecontent{      @jacksonxmlproperty(localname = "user_id")     private long userid;     private int result; } 

the problem occurs when serialize with

home home = new home(); home.sethandle(300023); logincontent content = new logincontent(); content.setuserid(300023); content.setresult(0); home.setcontent(content); xmlmapper xmlmapper = new xmlmapper(); xmlmapper.findandregistermodules(); string xmlstring = xmlmapper.writevalueasstring(home); 

xmlstring return xml correct fields incorrect order @jsonpropertyorder

<home>     <handle>300023</handle>     <content>         <user_id>300023</user_id>         <result>0</result>     </content>     <command>login</command> </home> 

the implementing class type of content based on value of <command>, in same level <content>, hence usage of jsontypeinfo.as.external_property. since deserialization working expected, excluded other implementing classes of basecontent. looking way can make @jsonpropertyorder effective fields generated @jsontypeinfo. have tried add command field in home.class, result in duplicated tag in xml.

what correct way achieve this? or there other better way of doing (serialize , deserialize mentioned xml content varies based on command value specific order)?

thanks in advance.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -