8

I am trying to come up with a set of documents for one of our projects where there is a requirement to convert Java POJOs to JSON Schema 4 and sometimes JSON schema 4 back to POJOs. I couldn't find a maven plug-in that does both of it.

I was able to find https://github.com/wodzuu/JSONschema4-mapper for JSON Schema generation and https://github.com/joelittlejohn/jsonschema2pojo for PoJo generation.

I am sure it is a very common use case, so just writing to check what you folks used to get past this? Any inputs

g0c00l.g33k
  • 2,458
  • 2
  • 31
  • 41

1 Answers1

0

I have been using jsonschema2pojo for a long time and am very supportive of this nice library and its tooling.

To generate JsonSchema out of POJO:

  • First, it should be very doable, for a POJO class can be converted to JSON using JSON serializing tools (jackson etc...). Just convert a sample of your POJO to JSON and jsonschema2pojo can generate a JSONSchema out of if. Other than that, integrating it to maven must be as easy as just executing a command in maven.
  • Second, you can submit a feature request to the developer. The community is very active..

Hope it helps.

myuce
  • 1,321
  • 1
  • 19
  • 29
  • Each conversion comes with losses and/or complexity (for implementation and maintenance). Inferring a schema from a JSON instance when you have access to the properly typed code is not the best idea. Rather use jsonschema2pojo only for what its name suggests and pick one of the various schema-from-code generators out there for the reverse. Also: four-and-a-half years (and three newer JSON schema draft versions) after the question was raised, this broad “what tools do you use” question doesn’t seem up-to-date anymore. – Carsten Apr 08 '20 at 04:47