jackson xml deserialize inline array

前端 未结 1 621
醉酒成梦
醉酒成梦 2021-02-20 09:04

How to deserialize such strange XML. In my opinion, the props-entity is missing (around the props), but I can\'t change the source of this XML (a web service).



        
相关标签:
1条回答
  • 2021-02-20 09:39

    It should be possible to handle "unwrapped" style of list elements with Jackson XML module 2.1, with @JacksonXmlElementWrapper(useWrapping=false).

    Structure should be something like this:

    @JacksonXmlRootElement(localName="parents")
    public class Parents {
      @JacksonXmlElementWrapper(useWrapping=false)
      public List<Parent> parent;
    }
    
    public class Parent {
      @JacksonXmlProperty(isAttribute=true)
      public String name;
    
      public String description;
    
      @JacksonXmlElementWrapper(useWrapping=false)
      public List<Prop> prop;
    }
    
    public class Prop {
      @JacksonXmlProperty(isAttribute=true)
      public String name;
    
      public String value;
    }
    

    so your solution was quite close.

    Note that if inner classes are used, they need to have 'static' in declaration. I tested this with 2.1.4, and it works for me.

    0 讨论(0)
提交回复
热议问题