Question

I'm using Jackson in a Spring application to deserialize JSON streams (coming from REST services) into POJOs. At the moment I use this web utility to generate the POJO from the JSON stream. The point is that in the future I will handle different JSON streams and I think it will become more and more complex and frustrating to generate POJOs for the different JSON streams.

Is there any way to let the project auto-generate the POJO starting from the JSON stream? For example the QueryDSL library provides a Maven plugin to generate the Q* classes used for query building. Does it exist a similar plugin for Jackson or any other way to make things done?

Thank you in previous

Giulio

Was it helpful?

Solution

The jackson documentation makes no mention of anything similar and I have never heard of anything like what you mention.

You mentioned QueryDSL which generates the Q* classes during the build phase. That means that you are willing take use extra steps to build your code, which means that you should't have any troubles using jsonschema2pojo's Maven or Gradle plugins

OTHER TIPS

Maybe there is something wrong with your REST design. REST endpoints should be very specific. Each rest endpoint should represent a resource, in other words, a domain/pojo that usually represents an entity of your data base.

If your endpoint receive more than one resource representation, you could end up with a huge DTO, very hard to maintain.

Usually, you build your domain model. These domains are regular pojos, so you would use them to convert json/java - java/json. This should scale well. Any modification to your model should affect your json stream as well. If you modify a domain, only the endpoint that represents this resource will take effect.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top