Tag Archives: @Jsonignoreproperties does not work

@Jsonignoreproperties does not work [How to Solve]

Define the class as follows.

import org.codehaus.jackson.annotate.JsonIgnoreProperties;

import org.codehaus.jackson.annotate.JsonProperty;

@JsonIgnoreProperties(ignoreUnknown = true)

public class TenantSpecialLinePo extends TenantLinePo

{

private static final long serialVersionUID = -1356444280247234290L;

private Integer tLineId;

……

}

Deserialization

import com.fasterxml.jackson.databind.ObjectMapper;

ObjectMapper objectMapper = new ObjectMapper();

list = objectMapper.readValue(msgObject.getString(“data”),TenantSpecialLinePo[].class);

Error:

Unrecognized field “azDeviceId” (class com.huawei.netmonitor.server.entity.tenantSpecilLine.TenantSpecialLinePo),not marked as ignorable

Searching the web, it turns out that the wrong version of jackson is mixed, org.codehaus.jackson.annotate (version 1.x), while the version of ObjectMapper is com.fasterxml. jackson.databind (version 2.x)

https://stackoverflow.com/questions/20986995/jsonignoreproperties-not-working

A closer look at the previous code shows why the original code did not report an error

import org.codehaus.jackson.map.ObjectMapper;

TenantSpecialLineResponseBean tenantSpecialLineResponseBean = objectMapper.readValue(in,TenantSpecialLineResponseBean.class);

 

It turns out that Jackson fasterxml is the new package name of Jackson 2.0, version 1.x now only provides bug-fix, while version 2.x is still under continuous development and release. If it is a new project, it is recommended to use 2x directly, i.e. fasterxml jackson.