I want to serialize some string json (I use Spring Boot):
{
"commandId": "34d3a914-a3d7-112a-bs37-3452ac130002",
"status": "SUCCESS",
"response": {
"prop1": "",
"prop2": "",
"prop3": "true",
"prop4": ""
}
}
My mapper:
private static final ObjectMapper mapper = new ObjectMapper();
public static <T> T fromJson(String json, TypeReference<T> type) {
T t;
try {
t = mapper.reader().forType(type).readValue(json);
} catch (IOException e) {
String message = "Error converting from json";
log.error(message, e);
throw new IllegalArgumentException(message);
}
The usage of the mapper:
final Command command =
JsonUtils.fromJson(json, new TypeReference<Command>() {});
Command class:
public class Command {
private UUID commandId;
private status status;
private String response;
private String error;
}
Currently I get the error:
com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `java.lang.String` out of START_OBJECT token
I want to save in Mongo db response
field as string and later on after receiving that object from DB I can deserialize the whole object. Is there any annotation to tell the Json mapper to not to serialize the structure inside the response
field?