How to add Jackson annotations to POJO generated from XSD by JAXB/XJC?

后端 未结 1 1614
我在风中等你
我在风中等你 2021-01-22 04:05

I\'m generating POJOs from XSDs using JAXB. And I\'m using Jersey/Jackson to serialize the POJOs to JSONs. For the whole project, I\'ve created an ObjectMapper that has In

1条回答
  •  一向
    一向 (楼主)
    2021-01-22 04:28

    If you just want to add one annotation, consider using my JAXB2 Annotate Plugin. See, for instance, this example, specifically this bindings file.

    In your case the bindings will look something like:

    
        
            @org.codehaus.jackson.map.annotate.JsonSerialize
                (include=org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion.ALWAYS)
        
    
    

    (Not tested, just a sketch.)

    Few hints:

    • Syntax is Java, but you have to use fully qualified class names.
    • Jackson JAR must be present in the XJC classpath, otherwise your annotations won't be found.

    SO disclaimer: I am the author of the mentioned plugin.

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