jackson-dataformat-xml icon indicating copy to clipboard operation
jackson-dataformat-xml copied to clipboard

xml数组个数转换错误

Open gisspace opened this issue 4 years ago • 2 comments

转换后当前是: image 应该是: image

gisspace avatar Apr 26 '21 03:04 gisspace

image

gisspace avatar Apr 26 '21 03:04 gisspace

Screenshots are bit problematic (I can't see the code), and without any description it is difficult to know if I understand the issue... but if the problem is that XML token stream model produces repeat keys, yes, this is true. Use of token stream level API is not something that is supported for general usage, and users need to be aware of some oddities there.

But I think that if you want to produce valid JSON from XML, you will need to either:

  1. Use an intermediate structure to read XML -- for example, JsonNode from ObjectMapper.readTree() -- and then write that. Binding to JsonNode or Object, with Jackson 2.12.3, should produce Arrays for repeated elements
  2. If using streaming API directly, add handling of duplicate keys; most likely to create implicit Array. This is what JsonNodeDeserializer does (as of Jackson 2.12)

cowtowncoder avatar Apr 26 '21 16:04 cowtowncoder