【发布时间】:2020-05-14 11:45:54
【问题描述】:
我正在尝试在 Java 应用程序中创建 Map>,但是在尝试反序列化时出现下一个错误:
com.fasterxml.jackson.databind.JsonMappingException: Unexpected end-of-input: expected close marker for Object (start marker at [Source: (String)"{"number":10000000,"person":{"person1":{"{\"Name\":\"test\", \"userId\":\"test1\", \"requestDate\":null}":2222}}}"; line: 1, column: 106])
at [Source: (String)"{"number":10000000,"person":{"test":{"{\"Name\":\"test\", \"userId\":\"test1\", \"requestDate\":null}":2222}}}"; line: 1, column: 191] (through reference chain: com.mycompany.mavenproject1.testClass["person"])
我创建了一个对象并向其中添加数据。之后我将它映射到字符串:
String personTest = map.writeValueAsString(myObject);
这是它生成的字符串:
{"number":10000000,"person":{"test":{"{\"Name\":\"test\", \"userId\":\"test1\", \"requestDate\":null}":2222}}}
我正在尝试将其反序列化为:
testClass t2 = map.readValue(personTest , testClass.class);
TestClass 是下一个:
@Data
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
public class testClass implements Serializable{
private final long number;
@JsonDeserialize(contentUsing=ExampleClassJsonDeserializer.class)
private Map<String, Map<Person, Long>> person;
public testClass(){
keepAliveTimeout = 10000000;
person = new HashMap();
}
}
【问题讨论】:
-
我猜 JSON 字符串有问题 请验证一次 {"number":10000000, "person":{ "test":[ {"Name":"test", "userId ":"test1", "requestDate":null} ]}} 我做了一些改变,现在看起来很好
-
@AshishSharma 字符串取自 String personTest = map.writeValueAsString(t);
标签: java serialization jackson hashmap