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
Support for deseralization with no type information. #16
Comments
Yes, you can use converter in property annotation. |
Will the databinding have to be done manually? The json structure may be different every time. |
Not sure what you mean by manually.
You can find working example at: https://github.com/ngs-doo/dsl-json/blob/master/examples/Maven/src/main/java/com/dslplatform/maven/Example.java#L33 |
Okay great I think that's what I'm looking for. However, in the case of your SupportArrayList example you call a method deserializeIntNullableCollection. As far as I know there is no equivalent for a Map on the NumberConverter class? |
Ah it's in the DslJson class, perfect. Thanks again. |
np :) |
Okay so using the following custom conversion class works fine apart from some unusual type resolving.
This converter, when deserializing the following JSON will resolve the field skippable into a Long, and the player_type field into a Big Decimal.
However, adding a trailing space to skippable's field value (as below) causes it to resolve into a BigDecimal along with player_type.
Is this expected behaviour? Is there any way to change how the types are resolved? Ideally the above JSON should resolve into ints. Thanks, |
Yes, this is the expected behavior. The issue is that in: https://github.com/ngs-doo/dsl-json/blob/master/library/src/main/java/com/dslplatform/json/NumberConverter.java#L1055 It's only an issue for this generic JSON parsing (when there are no types). |
If you wish to change how types are resolved... you'll have to write/copy paste your own number and map converters :( |
Hm... thinking about it some more... it's true that this could be improved... I'll look into it when I find some free time. |
Thanks, will code around the problem for now. Aside from that great work on the library |
I've released 1.2.1 with fixes for this |
Jackson will default to using LinkedHashMap to represent JSON where there is no type information given, or the type information is given as Object.class.
Is there any support for this type of behaviour with dsl-json?
I am looking to deserialize json where a field may have varying types. For example, in my model class I have an instance variable declared as Map<String, Object> fieldName. The object value may be represented in the JSON as a string, int, object or array etc. Does dsl-json support a method of generically deserializing this into some sort of structure so it can be accessed from the instance variable.
Here is an example of some JSON that I hope to deserialize into a Map<String, Object>
Thanks
The text was updated successfully, but these errors were encountered: