简体   繁体   中英

spring jackson Map Deserialization

I'm passing via a Spring controller a json object that looks like this:

{
  "dataset":"myDataset",
  "typeProperties":[
    "myProperty"
  ],
  "stopWords":{
    "de":[ "daß","allem","dem"],
    "fr":["salut"]
  }
}

The corresponding java object is:

public class DatasetConfigRequest {
    String dataset = "";
    List<String> typeProperties;
    HashMap<String,ArrayList<String>> stopWords = new HashMap<String,ArrayList<String>>();

//getter and setters

But when I pass it I get the following error:

JSON parse error: Cannot deserialize instance of `java.util.HashMap<java.lang.Object,java.lang.Object>` out of START_ARRAY token; nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `java.util.HashMap<java.lang.Object,java.lang.Object>` out of START_ARRAY token
 at [Source: (PushbackInputStream); line: 1, column: 104] (through reference chain: eu.qanswer.core2.server.controller.payload.dataset.DatasetConfigRequest["stopWords"])]

I understand that the problem is the HashMap with values a ArrayList. But how to solve this?

Thank you D063520

创建新类并将其命名为 stopWords 添加 id 和列表字段,最后向数据集类添加一个字段,将其命名为 stopWords

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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