简体   繁体   English

(没用吗?)带有jsonschema2pojo的Resource__类

[英](useless?) Resource__ classes with jsonschema2pojo

Familiar with Java and XML, I have tried to process JSON data. 熟悉Java和XML,我曾尝试处理JSON数据。 I'm using jsonschema2pojo to generate Plain Old Java Objects from example JSON data. 我正在使用jsonschema2pojo从示例JSON数据生成Plain Old Java Object。

Let's say I want to import products and categories from a webshop; 假设我要从网上商店导入产品和类别;

http://developers.seoshop.com/api/resources/product http://developers.seoshop.com/api/resources/category http://developers.seoshop.com/api/resources/product http://developers.seoshop.com/api/resources/category

jsonschema2pojo does its job, but what about all generated Resource, Resource_, Resource__, Resource____ etc. files? jsonschema2pojo可以完成工作,但是所有生成的Resource, Resource_, Resource__, Resource____ __ Resource, Resource_, Resource__, Resource____等文件呢?

在此处输入图片说明

All these Resource classes are equal. 所有这些Resource类都是相等的。 Can I just delete these (and replace them bij one Resource class)? 我可以删除它们(并用一个Resource类替换它们)吗? What is the reason for all these duplicated classes? 所有这些重复的类的原因是什么?

( don't mind the .json and .schema.json file they're just for investigation ) 不要介意仅用于调查的.json和.schema.json文件

If you have nested classes you can modify the ObjectRule.java and RuleFactory.java a bit. 如果您有嵌套的类,则可以稍微修改ObjectRule.java和RuleFactory.java。 I created a Hash of Class Name, JSON node and the package using MD5 algorithm and stored it in a map. 我使用MD5算法创建了“类名称”,“ JSON”节点和包的哈希,并将其存储在地图中。 Before creating any new class I just check if it's hash already exists in the hashMap in which case I just return the class corresponding to that hash. 在创建任何新类之前,我只是检查hashMap中是否已经存在其哈希,在这种情况下,我只返回与该哈希对应的类。

Check my commit here : mdfaizanali786/jsonschema2pojo@e5343db#diff-7fef584364765f2bd47a596ad18cecc4

If you have top level duplicate classes you can fetch the schema, jsonify it and then again do similar check that it is not identical. 如果您有顶级重复类,则可以获取该架构,对其进行json化,然后再次进行类似的检查以确保其不相同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM