Can I create classes from json data like jaxb

So, my code is an api client, the data is returned as xml, and Ive been able to create a valid xsd file from some examples of this xml, and then generate some JAXB classes from the circuit so that my code can now load and work with xml data without having to work directly with xml.

But, unfortunately, in the latest version of api they refused to support xml and only returned json. Is there a json process that I can do similar to the xml process?

If this is not possible from the schema, there are solutions, therefore, if I manually create my json classes, I can use them for automatic warfare in raw json data, so at least I need to deal only with json.

EDIT: Maybe https://github.com/ko5tik/jsonserializer would be helpful

UPDATE: FYI, so I looked at jsonschema2pojo, but this only creates pojos from the circuit, and I actually did not have a json scheme, but only the actual json. I tried to create a schema from the json example that I had, but did not get it for al to work, but the simplest example.

Then I looked at http://wiki.fasterxml.com/JacksonInFiveMinutes , Jackson could use pojos created by jsonschema2pojo if Id managed to get it working. So I tried to follow the example and created a POJO based on the json data that I had, and it was pretty simple, then I tried the full data binding using this, and it worked for the first time.

So, in general, I'm going to use Jackson to work with json returned by the web service, I have to manually create a POJO for each object, but at least it works.

+5
source share
4 answers

POJO JSON , () ruby ​​ script, . : fooobar.com/questions/25137/...

github: https://github.com/wotifgroup/json2pojo

+1

, ... JSON , .

: , (), , .

0

I don’t think there is a JSON equivalent of XSD, and it does what you ask is very difficult to implement. For starters, a generator program cannot reliably infer Java types that should be used for attributes of a JSON object. (In the case of XML, you drew these conclusions and expressed them in the corresponding XSD.)

0
source

All Articles