简体   繁体   English

如何从xsd生成Json兼容的POJO

[英]How to generate Json compatible POJO from xsd

I have been using xsd to prepare data transfer model. 我一直在使用xsd来准备数据传输模型。 By now we were ok to use XML format and hence were using xjc to generate the same (using maven plugin). 到现在为止,我们可以使用XML格式,因此使用xjc生成相同的内容(使用maven插件)。

Now we need to move way from XML and use Json. 现在我们需要从XML转移并使用Json。 Is there a plugin or better way with which u still use xsd and generate Json compatible model with proper annotations like @JsonRootName, @JsonInclude etc. 是否有插件或更好的方法,你仍然使用xsd并生成Json兼容模型与适当的注释,如@JsonRootName,@ JsonInclude等。

Jackson 2 is able to recognize JAXB annotations (which are generated by xjc): https://github.com/FasterXML/jackson-modules-base/tree/master/jaxb Jackson 2能够识别JAXB注释(由xjc生成): https//github.com/FasterXML/jackson-modules-base/tree/master/jaxb

So by using Jackson as preferred serializer, all your existing Pojo's will automatically - and with no cost - become JSON friendly ! 因此,通过使用Jackson作为首选的序列化器,所有现有的Pojo都将自动 - 并且无需任何成本 - 成为JSON友好的!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM