com.fasterxml.jackson.databind.exc.MismatchedInputException jackson json转实体 com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException

jackson json转实体 com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException

jackson 2.2.2

由于vo中缺少json的某个字段属性引起

3种解决方法

1、 vo中添加注解 @JsonIgnoreProperties(ignoreUnknown = true),在实体类上加上注解

2、  mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);

3、 添加如下即可:mapper.configure(DeserializationFeature.ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT, true);,把空的数组“[]”转为空

com.fasterxml.jackson.databind.exc.MismatchedInputException

错误的格式

[{
    "firstName": "hgf",
    "lastName": "frew",
    "username": "erf",
    "email": "bgghjk",
    "password": "bgte",
    "role": "trrere"
  }
]

  

正确的格式,不要[]

{
    "firstName": "hgf",
    "lastName": "frew",
    "username": "erf",
    "email": "bgghjk",
    "password": "bgte", "role": "trrere" }

 

jackson 2.2.2

由于vo中缺少json的某个字段属性引起

3种解决方法

1、 vo中添加注解 @JsonIgnoreProperties(ignoreUnknown = true),在实体类上加上注解

2、  mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);

3、 添加如下即可:mapper.configure(DeserializationFeature.ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT, true);,把空的数组“[]”转为空

com.fasterxml.jackson.databind.exc.MismatchedInputException

错误的格式

[{
    "firstName": "hgf",
    "lastName": "frew",
    "username": "erf",
    "email": "bgghjk",
    "password": "bgte",
    "role": "trrere"
  }
]

  

正确的格式,不要[]

{
    "firstName": "hgf",
    "lastName": "frew",
    "username": "erf",
    "email": "bgghjk",
    "password": "bgte", "role": "trrere" }

 

猜你喜欢

转载自www.cnblogs.com/tarena/p/9157444.html