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

[Question] Deserialize data with mixed mode attribute #286

Open
mark-b2c2 opened this issue Mar 22, 2025 · 1 comment
Open

[Question] Deserialize data with mixed mode attribute #286

mark-b2c2 opened this issue Mar 22, 2025 · 1 comment

Comments

@mark-b2c2
Copy link

Hi,
I need to deserialize data from an external provider where I have no control of the format and one of the attributes can be an array or an object.

Sample data:

{"type":"snapshot","data": [{"name": "John"},{"name":"Jane"}]}

and

{"type":"update","data": {"name": "John"}}

I have tried creating a POJO class with constructors supporting both object and array format, i.e. Data and Data[]
I have tried creating variations using a mix of constructors and setters.
I started to look at mixins but I didn't get very far as documentation and sample code referring to mixins is minimal.

I have created many converters to serialize/deserialize many custom data types like timestamps for example. Would a custom converter or more specifically a custom JsonReader.ReadObject be required?

Is it supported using dsl_json in any way?

More generally, I have often wanted to optionally deserialize data based on the presence of an attribute and have never managed to figure out if it was possible.

As always, thanks for all your effort in a great library!

@zapov
Copy link
Member

zapov commented Apr 9, 2025

Can you please provide a test case and I'll take a look

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