我想序列化一些字符串json(我使用Spring Boot):
{
"commandId": "34d3a914-a3d7-112a-bs37-3452ac130002",
"status": "SUCCESS",
"response": {
"prop1": "",
"prop2": "",
"prop3": "true",
"prop4": ""
}
}
我的映射器:
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);
}
映射器的用法:
final Command command =
JsonUtils.fromJson(json, new TypeReference<Command>() {});
命令类:
public class Command {
private UUID commandId;
private status status;
private String response;
private String 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?