Java jackson反序列化嵌套对象HttpMessageEndableException:“0”;无法读取JSON:无法识别的字段…”;
我有一个这样的模型:Java jackson反序列化嵌套对象HttpMessageEndableException:“0”;无法读取JSON:无法识别的字段…”;,java,json,spring-mvc,jackson,Java,Json,Spring Mvc,Jackson,我有一个这样的模型: ... private TestClass test; public TestClass getTest(){ return test; } @JsonDeserialize(using = JsonDeserializerTest.class) public void setTest(TestClass test){ this.test = test; } 这是我的TestClass: public class TestClass{
...
private TestClass test;
public TestClass getTest(){
return test;
}
@JsonDeserialize(using = JsonDeserializerTest.class)
public void setTest(TestClass test){
this.test = test;
}
这是我的TestClass
:
public class TestClass{
private Integer field1;
private Integer field2;
public Integer getField1() {
return field1;
}
public void setField1(Integer field1) {
this.field1 = field1;
}
public Integer getField2() {
return field2;
}
public void setField2(Integer field2) {
this.field2 = field2;
}
}
最后是jsonderializertest
:
@Component
public class JsonDeserializerTest extends JsonDeserializer<TestClass> {
@Override
public TestClass deserialize(JsonParser jp, DeserializationContext dc) throws IOException, JsonProcessingException {
TestClass test = new TestClass();
//do some login
return test;
}
}
我怎样才能解决这个问题
另外,我在模型中使用了
@JsonProperty
在TestClass
之上,但问题没有解决。它说classMyModel
,而不是TestClass
。
Could not read JSON: Unrecognized field "field1" (class ***.***.MyModel), not marked as ignorable