10 分钟 jackjson 配置

https://github.com/FasterXML/jackson-databind/


mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);

------------------------

public class MyValueBean {
private String name;
public MyValueBean() {
// TODO Auto-generated constructor stub
}
public MyValueBean( String name) {
// TODO Auto-generated constructor stub
this.name = name;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}


}

public class JackjsonCfg {
public static void main(String[] args) throws Exception {
ObjectMapper mapper = new ObjectMapper();

mapper.readValue("{\"name\":88, \"age\":13}", MyValueBean.class);
}
}



xception in thread "main" com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "age" (class com.wengmd.mdstjackjson.MyValueBean), not marked as ignorable

----------------------

import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;

public class JackjsonCfg {
public static void main(String[] args) throws Exception {
ObjectMapper mapper = new ObjectMapper();
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
mapper.readValue("{\"name\":88, \"age\":13}", MyValueBean.class);
}
}

你可能感兴趣的:(json)