我可以从类似于jaxb的json数据创建类 [英] Can I create classes from json data similar to jaxb

查看:84
本文介绍了我可以从类似于jaxb的json数据创建类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我的代码是api的客户端,数据以xml的形式返回,我已经能够从该xml的一些示例创建有效的xsd文件,然后从模式生成一些JAXB类,这样我的代码现在可以加载使用xml数据而无需直接使用Xml。

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

但遗憾的是,在最新版本的api中,他们已经删除了xml支持并且只返回json。是否有一个类似于我的xml进程的json进程?

But unfortunately in the latest version of the api they have dropped xml support and only return json. Is there a json process I can do analogous to my xml process ?

如果从架构中不可能有解决方案,那么如果我手动创建我的json类,我他们可以使用它们来自动处理原始json数据,所以至少我只需要处理一次json。

If its not possible from a schema are there solutions so that if I manually create my json classes, I can them use them to automatically martial in raw json data, so at least I only have to deal with json once.

编辑:可能https://github.com/ko5tik/jsonserializer 会很有用

更新:仅供参考我所以看了jsonschema2pojo,但只从模式创建pojos,我实际上没有json模式,只是实际的json。我开始创建一个来自我所拥有的示例json的模式,但是没有让它为al工作但是最简单的例子。

UPDATE:FYI so I looked at jsonschema2pojo but that only creates pojos from a schema, and I didnt actually have a json schema, just the actual json. I had a go at creating a schema from the example json I had but didnt get it working for al but the simplest example.

然后我看了http://wiki.fasterxml.com/JacksonInFiveMinutes ,杰克逊能够使用jsonschema2pojo创建的pojos,如果我设法让它工作。所以我接着尝试了下面的例子并根据我的json数据创建了一个POJO,这很简单,然后我尝试使用它完全数据绑定,并且它第一次工作。

I then looked at http://wiki.fasterxml.com/JacksonInFiveMinutes , Jackson would have been able to use the pojos created by jsonschema2pojo if Id managed to get it working. So I then tried following the example and created a POJO based on the json data I had and it was quite easy, then I then tried full data binding using this and it worked first time.

总而言之,我将使用Jackson来处理webservice返回的json,我将不得不为每个实体手动创建一个POJO,但至少它可以工作。

So in summary Im going to use Jackson for dealing with json returned by the webservice, I'll have to manually create a POJO for each entity but at least it works.

推荐答案

至于回答,也许可以尝试 jsonschema2pojo

As to answer, maybe try "jsonschema2pojo".

但之前已经提出了类似的问题:

But similar questions have already been asked before:

  • How can I parse a JSON schema and create a default json object or generate a java class?
  • Generate Java class from JSON?
  • Is there a tool to generate a JSON schema from an XML schema through Java?

这篇关于我可以从类似于jaxb的json数据创建类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆