有誰知道com.fasterxml.jackson.databind.ObjectMapper如何能夠將JSON屬性映射到POJO屬性不區分大小寫?不區分大小寫的JSON到POJO映射而不改變POJO
JSON字符串:
[{"FIRSTNAME":"John","LASTNAME":"Doe","DATEOFBIRTH":"1980-07-16T18:25:00.000Z"}]
POJO級:
public class Person {
private String firstName;
private String lastName;
private Date dateOfBirth;
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public Date getDateOfBirth() {
return dateOfBirth;
}
public void setDateOfBirth(Date dateOfBirth) {
this.dateOfBirth = dateOfBirth;
}
}
測試類:
@Test
public final void testDeserializingPersonJsonToPersonClass()
throws JsonParseException, JsonMappingException, IOException {
final String jsonAsString = "[{\"FIRSTNAME\":\"John\",\"LASTNAME\":\"Doe\",\"DATEOFBIRTH\":\"1980-07-16T18:25:00.000Z\"}]";
final ObjectMapper mapper = new ObjectMapper();
final Person person = mapper.readValue(jsonAsString, Person.class);
assertNotNull(person);
assertThat(person.getFirstName(), equalTo("John"));
}
這以下錯誤結束:
com.fasterxml。 jackson.databind.JsonMappingException:無法反序列化的實例...
無法更改JSON-String和POJO-Class。
*這是不可能改變既不JSON字符串也不POJO級*,那麼它是不可能的。 – 2014-09-26 11:51:45