jsonSchema2pojo jackson deserialisation issue

半世苍凉 提交于 2019-12-24 20:12:06

问题


I am trying use jsonSchema2pojo POJO generating library and i am successful in doing so as well. But issue i am facing is deserialisation Exception when i try to generate map by typeReferencing generated rootClass i.e EsRootDoc(in below code).

Here , is the code that i am testing:

JCodeModel codeModel = new JCodeModel();
String classLocation = System.getProperty("user.dir")+ "/src/main/java";
GenerationConfig config = new DefaultGenerationConfig() {
                @Override
                public boolean isGenerateBuilders() { // set config option by overriding method
                    return true;
                }

                @Override
                public SourceType getSourceType() {
                    return SourceType.JSON;
                }
final RuleFactory ruleFactory = new RuleFactory(config,
            new Jackson2Annotator(config), new SchemaStore());

            final SchemaMapper mapperSchema = new SchemaMapper(ruleFactory,new SchemaGenerator());

    mapperSchema.generate(codeModel, "EsRootDoc",           "com.tech.EnrichmentService.EnrichmentController.tempJsonToClass", json);

codeModel.build(new File(classLocation));

ObjectMapper mapper = new ObjectMapper();
try{

     p = mapper.readValue(json,new TypeReference<com.tech.EnrichmentService.EnrichmentController.tempJsonToClass.EsRootDoc>() {});

    }
    catch(Exception e){
    e.printStackTrace();
    }

Exception :

  com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.lang.String out of START_ARRAY token
 at [Source: java.io.StringReader@72b070e8; line: 1, column: 15974] (through reference chain: com.tech.EnrichmentService.EnrichmentController.tempJsonToClass.EsRootDoc["svo"]->java.util.ArrayList[1]->com.tech.EnrichmentService.EnrichmentController.tempJsonToClass.Svo["svoMetadata"]->com.tech.EnrichmentService.EnrichmentController.tempJsonToClass.SvoMetadata["event"])

Now, If i am generating classes here and then typeReferencing same generated rootClass , how do i get to dissimilar json to Pojo issue ??

Editted(added json):

{
  "coref": [
    {
      "endOffset": 260,
      "coreference": "Hind Times",
      "entity": "them",
      "beginOffset": 256
    }
  ],

  "upCategory": "News",
  "dateFacet": "2016-06-14T04:14:06Z",
  "svo": [
    {
      "clause": "kids go missing from ? forest",
      "svoMetadata": {
        "sentenceID": 1,
        "clauseId": 2,
        "svoId": 0
      },
      "objectPOS": "IN POS NN NN",
      "isRelatedKeySVO": false,
      "subjectPOS": " NNS",
      "subject": "kids",
      "confidence": 0.786255231995661,
      "verb": "missing",
      "verbPOS": "VBG",
      "source": "OpenIE4",
      "isKeySVO": true,
      "object": "from ' forest toilet"
    },
    {
      "clause": "lack of toilets forced them to defacate in the open",
      "svoMetadata": {
        "sentenceID": 1,
        "clauseId": 0,
        "event": [
          "forced"
        ],
        "svoId": 0,
        "verbType": "event,"
      }
    }
  ],
    "projectName": "guest",
  "uniqueId": "575f848ee4b0011ac0e1ef091"
}

来源:https://stackoverflow.com/questions/44648092/jsonschema2pojo-jackson-deserialisation-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!