jackson Unrecognized field

Jackson provides a few different mechanisms to configure handling of "extra" JSON elements. Following is an example of configuring the ObjectMapper to not FAIL_ON_UNKNOWN_PROPERTIES.

jackson Unrecognized field
import org.codehaus.jackson.annotate.JsonAutoDetect.Visibility;
import org.codehaus.jackson.annotate.JsonMethod;
import org.codehaus.jackson.map.DeserializationConfig;
import org.codehaus.jackson.map.ObjectMapper;

public class JacksonFoo
{
  public static void main(String[] args) throws Exception
  {
    // { "aaa":"111", "bbb":"222", "ccc":"333" }
    String jsonInput = "{ \"aaa\":\"111\", \"bbb\":\"222\", \"ccc\":\"333\" }";

    ObjectMapper mapper = new ObjectMapper().setVisibility(JsonMethod.FIELD, Visibility.ANY);
    mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);

    Test test = mapper.readValue(jsonInput, Test.class);
  }
}

class Test
{
  String aaa;
  String bbb;
}
jackson Unrecognized field

For other approaches, see http://wiki.fasterxml.com/JacksonHowToIgnoreUnknown

jackson Unrecognized field

上一篇:C# 颜色有3种表示方式: 6位16进制、RGB、 颜色关键字


下一篇:import-module的注意事项与NDK_MODULE_PATH的配置