我在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”。