10

I have been using xsd to prepare data transfer model. By now we were ok to use XML format and hence were using xjc to generate the same (using maven plugin).

Now we need to move way from XML and use 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.

M.J.
  • 16,266
  • 28
  • 75
  • 97
  • 1
    Maybe you could provide some example with XSD and resulting bean with annotations? You perhaps need to switch from XSD to [JSON schema](https://json-schema.org/) ([this can be automated](https://stackoverflow.com/questions/3922026/generate-json-schema-from-xml-schema-xsd)). Once you have JSON schema there are some bean generators available (like [this one](https://github.com/Collaborne/json-schema-bean-generator) or [this one](http://www.jsonschema2pojo.org/)). Not sure if there is a maven plugin for this. Or you could switch to OpenAPI specs that are not bound to a specific format. – dpr Mar 13 '19 at 11:57

1 Answers1

1

Jackson 2 is able to recognize JAXB annotations (which are generated by 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 !

TacheDeChoco
  • 3,683
  • 1
  • 14
  • 17