Let's say I have the following Json data, here I have the id of type integer, and in Java class the type of id is String.
{
"id": 1,
"name": "user1"
}
@lombok.Data
@AllArgsConstructor
@NoArgsConstructor
class Data {
String id;
String name;
}
I want to convert the Json to the that class while strictly checking if the Json property's value is of same type as the class field.
String json = "{\"id\":1,\"name\":\"user1\"}";
ObjectMapper objectMapper = new ObjectMapper(new JsonFactory());
Data data = objectMapper.readValue(json, Data.class);
System.out.println(data);
Data(id=1, name=user1)
I want that here the conversion shouldn't happen but it gets converted.