Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Xml to Json array #16

Closed
stesteau opened this issue Feb 7, 2014 · 2 comments
Closed

Xml to Json array #16

stesteau opened this issue Feb 7, 2014 · 2 comments

Comments

@stesteau
Copy link

stesteau commented Feb 7, 2014

When converting XML to Json, if an element has only one child it won't be interpreted as a collection and it can cause problems:

i.e.

<foo>
  <bar>1</bar>
  <bar>1</bar>
  <bar>1</bar>
</foo>

will be converted to:


{ foo: [ {bar: 1}, {bar: 1}, {bar: 1} ] }

But,

<foo>
  <bar>1</bar>
</foo>

will be converted to:


{ foo: {bar: 1} }

So is there a way to tell XMLSerializer that an element should be an array?

@aalmiray
Copy link
Collaborator

XMLSerializer cannot decide in this case if a single child element constitutes an object property or a single element in an array. There must be a hint that elements within foo should be treated as array elements.

rac2030 added a commit to rac2030/Json-lib that referenced this issue Aug 21, 2014
Implemented list of elements which enforce creation of an array from
it’s childs even if there is no, only one or multiple elements with
different name in it.
In case of different name, information gets lost but it will be done
with a log warning.
@rac2030
Copy link
Contributor

rac2030 commented Aug 21, 2014

See #22 for implementation and unit tests.
As discussed with @aalmiray the elements in the array are just values without the names.
In case child elements have different types, conversion will be done anyway but there will be a log warning that the output may not be unserializable again to the same state.

aalmiray added a commit that referenced this issue Aug 22, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants