eserating-chwy / siren4j

Java library for the Siren Hypermedia Type Specification
MIT License
25 stars 15 forks source link

ReflectingConverter does support type conversion #4

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Simple example to reproduce:
1. Create a CollectionResource, set "total" property and serialize it to json 
string
2. Try to deserialized this string back to entity
3. exception occurs about incorrect type

The reason is that CollectionResource has total property of type long, but all 
non fractioned numbers are deserialized as Integer. During assignment this 
error occurs

Dirty workaround for this problem is to subclass and define setter with int 
type, but it's not a good solution

Please perform type conversion for at least simplest cases (like described) or 
use some existing solutions (for example Spring converters)

Original issue reported on code.google.com by zeldigas on 6 May 2014 at 7:43

GoogleCodeExporter commented 9 years ago
missed *not* in title, currently ReflectingConverter does *not* support type 
conversion

Original comment by zeldigas on 6 May 2014 at 7:45

GoogleCodeExporter commented 9 years ago
Thanks for catching this. I will make sure this gets addressed for the next 
release. 

Original comment by sire...@gmail.com on 10 May 2014 at 12:44

GoogleCodeExporter commented 9 years ago
This is not actually the ReflectingConverter. This is getting the json string 
to become   an Entity object which is done by Jackson. Still looking into 
getting this to work correctly.

Original comment by sire...@gmail.com on 20 May 2014 at 7:30

GoogleCodeExporter commented 9 years ago
Json just convert string to Entity which is to abstract to provide enough 
information about types of properties. This info is contained in the next 
"layer", in resources where we mark properties with annotations and can find 
out of what type this property should be.

Original comment by Pavlov.D...@gmail.com on 27 May 2014 at 6:31

GoogleCodeExporter commented 9 years ago
Sorry, typo again, I mean: Jackson just convert...

Original comment by Pavlov.D...@gmail.com on 27 May 2014 at 6:32

GoogleCodeExporter commented 9 years ago
I tried reproducing this by creating a CollectionResource setting the total 
value, serializing to a json string and then back toObject. I get no exception 
and the value of the total field is set correctly. 

Original comment by merolla....@gmail.com on 27 May 2014 at 12:46