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

Fail to deserialize byte fields #38

Closed
salyh opened this issue Jan 12, 2015 · 1 comment
Closed

Fail to deserialize byte fields #38

salyh opened this issue Jan 12, 2015 · 1 comment

Comments

@salyh
Copy link

salyh commented Jan 12, 2015

private byte numByte;

numByte = (byte) 6;

getter/setters omitted

JSON:
"numByte":6

Caused by: com.owlike.genson.JsonBindingException: Could not deserialize to property 'numByte' of class class model.Simple
    at com.owlike.genson.reflect.PropertyMutator.couldNotDeserialize(PropertyMutator.java:49)
    at com.owlike.genson.reflect.PropertyMutator.deserialize(PropertyMutator.java:32)
    at com.owlike.genson.reflect.BeanDescriptor.deserialize(BeanDescriptor.java:109)
    at com.owlike.genson.reflect.BeanDescriptor.deserialize(BeanDescriptor.java:92)
    at com.owlike.genson.convert.NullConverter$NullConverterWrapper.deserialize(NullConverter.java:56)
    at com.owlike.genson.convert.CircularClassReferenceConverterFactory$CircularConverter.deserialize(CircularClassReferenceConverterFactory.java:30)
    at com.owlike.genson.convert.DefaultConverters$ArrayConverter.deserialize(DefaultConverters.java:264)
    at com.owlike.genson.convert.NullConverter$NullConverterWrapper.deserialize(NullConverter.java:56)
    at com.owlike.genson.reflect.PropertyMutator.deserialize(PropertyMutator.java:30)
    ... 27 more
Caused by: com.owlike.genson.stream.JsonStreamException: Expected a String to convert to byte array found INTEGER
    at com.owlike.genson.stream.JsonReader.valueAsByteArray(JsonReader.java:298)
    at com.owlike.genson.convert.DefaultConverters$ByteConverter.deserialize(DefaultConverters.java:570)
    at com.owlike.genson.convert.DefaultConverters$ByteConverter.deserialize(DefaultConverters.java:557)
    at com.owlike.genson.convert.NullConverter$NullConverterWrapper.deserialize(NullConverter.java:56)
    at com.owlike.genson.reflect.PropertyMutator.deserialize(PropertyMutator.java:30)
    ... 34 more
@EugenCepoi
Copy link
Contributor

Hey @salyh thanks for reporting this.
In fact a single byte is ser/de with the same mechanism as a byte array (base64 encoded string). The idea was to stay symmetric.
However it is unoptimal, I am changing it to ser/de a single byte as an integer.
It could be made configurable, but maybe not worth to surcharge the API with additional options, until someone needs 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

2 participants