The json string is like this:
[
{
"id":1545043316459,
"user_id":127118102570729472,
"username":"abcd",
"phone":"12413453563",
"password":"b6b33aad5c337315d4ac5a34d82db990cfaf22e5eefe27220b6827d5e66ad8b4",
"license":"12351331",
"plate":"abcdef",
"avatar":"",
"approval":0,
"balance":0.0
}
]
When I use ObjectMapper.convertValue()
to convert this json to a List<User>
, the method returns null. However, when I changes the field "approval" to 1, the convertion succeeds.
Th class User
's constructor is as below:
@JsonCreator
public User(@JsonProperty("user_id") long userId, @JsonProperty("username") String username, @JsonProperty("password") String password, @JsonProperty("avatar") String avatar,
@JsonProperty("phone") String phone, @JsonProperty("license") String license, @JsonProperty("plate") String plate, @JsonProperty("approval") int approval,
@JsonProperty("balance") BigDecimal balance) {
this.userId = userId;
this.username = username;
this.password = password;
this.avatar = avatar;
this.phone = phone;
this.license = license;
this.plate = plate;
this.balance = balance;
this.approval = approval;
}
I have applied @JsonIgnoreProperties(ignoreUnknown = true)
to the class.