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

Add support for implicit array serialization #38

Open
natenobility opened this issue Dec 18, 2013 · 1 comment
Open

Add support for implicit array serialization #38

natenobility opened this issue Dec 18, 2013 · 1 comment

Comments

@natenobility
Copy link

It should be possible to parse an array of objects even if the corresponding value in the dictionary is not an array. A use case is as follows: you parse xml that is designed to be an array but only has a single element. The xml parser has no knowledge of the array intention, and most will just parse this to a dictionary, not an array of one element. This library, however, can actually convert these properly with no additional configuration as it knows the target property is an array type. To clarify further with an example:

This json can be parsed into a user with an array of one tweet:

{
"name": "Diego Chohfi",
"tweets": [
{
"id_str": 190957570511478800,
"text": "Tweet text"
}
]
}

However, this too should be parseable as a user with an array of one tweet (provided you specify an array mapping for property "tweets" of course), but I don't see a way to do it currently:

{
"name": "Diego Chohfi",
"tweets":
{
"id_str": 190957570511478800,
"text": "Tweet text"
}
}

@tomasebrennan
Copy link

Can I add a request for this as well. I have a very similar issue whereby our JSON we get back can either be a list of "tweets" or a single "tweet", like so:
{
"tweet" : {
"id_str": 190957570511478800,
"text": "Tweet text"
}

{
"tweets" : [ {
"id_str": 190957570511478800,
"text": "Tweet text"
},
{
"id_str": 190957570511478800,
"text": "More Tweet text"
},
]
}

At the moment I can use DCArrayMapping for the second example but I would like some implicit mapping for the first example as suggested by the OP.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants