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.
Similar Posts:
- [Solved] com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field “FileSi…
- [Solved] Java.io.EOFException: No content to map to Obje…
- Springboot is compatible with jackson.databind and reports errors [How to Solve]
- com.fasterxml.jackson.databind.exc.InvalidDefinitionException: No serializer found for class tonels.
- [How to Solve] jackson not marked as ignorable
- [Solved] com.fasterxml.jackson.core.JsonParseException: Illegal unquoted character ((CTRL-CHAR, code 10)): ha
- [Solved] Interpreter error /com.fasterxml.jackson.databind.JavaType
- [Solved] swagger Document Error: For input string: “”
- [Solved] No serializer found for class XXX and no properties discovered to create BeanSerializer
- [Solved] Using Jackson string to convert entity to report error: mismatchedinput exception: cannot construct instance of