是否可以看到 Jackson Annotations 创建的 JSON?
Is it possible to see the JSON created by Jackson Annotations?
我在 Spring 5 项目中使用 https://github.com/FasterXML/jackson-annotations。
我在向服务器发送数据时遇到了一些问题,因为序列化对象的某些字段格式不正确。
是否可以看到 Jackson Annotations 创建的 JSON?这将使我更容易看到发送到我需要使用的 API 的 JSON 表示有什么问题。
你可以试试这个 -
ObjectMapper mapper = new ObjectMapper().enable(SerializationFeature.INDENT_OUTPUT);
try {
String json = mapper.writeValueAsString(<your-class-here>);
System.out.println(json);
} catch (JsonProcessingException e) {
e.printStackTrace();
}
只需将 "your-class-here" 替换为您生成的对象引用即可。
我在 Spring 5 项目中使用 https://github.com/FasterXML/jackson-annotations。 我在向服务器发送数据时遇到了一些问题,因为序列化对象的某些字段格式不正确。 是否可以看到 Jackson Annotations 创建的 JSON?这将使我更容易看到发送到我需要使用的 API 的 JSON 表示有什么问题。
你可以试试这个 -
ObjectMapper mapper = new ObjectMapper().enable(SerializationFeature.INDENT_OUTPUT);
try {
String json = mapper.writeValueAsString(<your-class-here>);
System.out.println(json);
} catch (JsonProcessingException e) {
e.printStackTrace();
}
只需将 "your-class-here" 替换为您生成的对象引用即可。