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

BigDecimal Json View Issues #23

Closed
twiz911 opened this issue Mar 16, 2016 · 5 comments
Closed

BigDecimal Json View Issues #23

twiz911 opened this issue Mar 16, 2016 · 5 comments

Comments

@twiz911
Copy link

twiz911 commented Mar 16, 2016

Hi

Your library does exactly what we were looking for. However, we've noticed enabling it changes our BigDecimal field JSON from:

"latitude": 9874359834.345,

to:

"latitude": { "intVal": null, "scale": 3, "precision": 13, "stringCache": null, "intCompact": 9874359834345 },

How can we restore it back to the initial version?

Thanks

@twiz911
Copy link
Author

twiz911 commented Mar 16, 2016

The fix appears to be adding handling BigDecimal in JsonViewSerializer.writePrimitive()

@monitorjbl
Copy link
Owner

Yeah, that'd be the fix. If you want to open a pull request, feel free. Otherwise I'll try to get this taken care of in the next couple weeks.

@twiz911
Copy link
Author

twiz911 commented Mar 16, 2016

Thanks. Actually I'm not sure how to fix as now when I try to deserialize the JSON I get the error

Can not deserialize instance of java.math.BigDecimal out of START_OBJECT token

Any advice? Thanks

@monitorjbl
Copy link
Owner

The problem is that you want to represent a BigDecimal as a primitive number like

{
  "myField" : 254.984
} 

The serializer is (correctly) treating BigDecimal as an object, because it is one. BigDecimal is typically used in place of double, but it doesn't have JAXB binding methods so by default it will not be deserializable which is why you get that error.

The JsonViewSerializer just needs to be updated to serialize/deserialize BigDecimal as a primitive instead of an object.

monitorjbl added a commit that referenced this issue Jun 7, 2016
@monitorjbl
Copy link
Owner

This is now available in version 0.12 in Maven Central.

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