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

Jettison serialize array object as like json object when array object contains only one element in it. #83

Open
aweseeker opened this issue Sep 29, 2023 · 0 comments

Comments

@aweseeker
Copy link

aweseeker commented Sep 29, 2023

When using JettisonMappedXmlDriver driver for serializing with jettsion 1.5.4 version, it serialize array object as json object when array object contains only one element in it, if it contains more than 1 element it is serialized as array object

For example: here donneesFlexibles is a list and when it contains only one element it is serialized in response as object(like json object) instead of array object

'donneesFlexibles' contains single element and it is serialized as like json object by wrapping it with { } around single element (note: when it has more than 1 element, it is serialized as array)

"donneesFlexibles": {
                            "@class": "linked-list",
                            "com.test.DonneeFlexible": {
                                "cle": "numeroInternational",
                                "valeur": "non"
                            }
                        }

When the same object serialized by JsonHierarchicalStreamDriver: -- here it has [ ] around single element which represent donneesFlexibles as array even if it contains only one element

"donneesFlexibles": [
                        {
                            "cle": "numeroInternational",
                            "valeur": "non"
                        }
                    ]

While parsing this type of response, consumer may get typeError when expecting array but got object
May we know is there any reason for designing jettsion serialization this way ? It would be more meaningful if we represent the object structure as its data type irrespective of the number of elements in it.

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

1 participant