Jackson JSON 反序列化:每行中的数组元素 [英] Jackson JSON Deserialization: array elements in each line
问题描述
我正在使用 Jackson 并且想要漂亮地打印 JSON,以便数组中的每个元素都转到每一行,喜欢:
<前>{"foo" : "酒吧",等等":[1、2、3]}设置 SerializationFeature.INDENT_OUTPUT
true 只会为对象字段插入换行符,而不是数组元素,以这种方式打印对象:
有谁知道如何实现这一目标?谢谢!
您可以扩展 DefaultPrettyPrinter 并覆盖方法 beforeArrayValues(…) 和 writeArrayValueSeparator(…) 以存档所需的行为.之后,您必须通过 setPrettyPrinter(…).
I am using Jackson and would like to pretty-print JSON such that each element in arrays goes to each line, like:
{ "foo" : "bar", "blah" : [ 1, 2, 3 ] }
Setting SerializationFeature.INDENT_OUTPUT
true only inserts newline characters for object fields, not array elements, printing the object in this way instead:
{ "foo" : "bar", "blah" : [1, 2, 3] }
Does anyone know how to achieve this? Thanks!
You could extend the DefaultPrettyPrinter and override the methods beforeArrayValues(…) and writeArrayValueSeparator(…) to archieve the desired behaviour. Afterwards you have to add your new Implementation to your JsonGenerator via setPrettyPrinter(…).
这篇关于Jackson JSON 反序列化:每行中的数组元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!