-
Notifications
You must be signed in to change notification settings - Fork 17
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
Fix JsonNumber bson serialization #898
Fix JsonNumber bson serialization #898
Conversation
- Always use the right number type when serializing, so formats that support the type info can deserialize to the correct type - Fix fallback deserialization of custom Number implementations - Fix element index increment when serializing BigInteger
@@ -279,6 +279,11 @@ protected Number getBestNumber() { | |||
}; | |||
} | |||
|
|||
@Override | |||
protected BigDecimal getBigDecimalFromNumber(Number number) { | |||
return ((Decimal128) number).bigDecimalValue(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be implemented using instanceOf or different convertions
* @throws UnsupportedOperationException If custom number types are not expected | ||
*/ | ||
protected BigDecimal getBigDecimalFromNumber(Number number) { | ||
throw new UnsupportedOperationException(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Definitely needs a proper default implementation.
Thanks for the PR. I have corrected the new method. |
int JsonNumber
, when deserializing you get along JsonNumber
.Number
implementations. The bson decoder advances whengetBigDecimal
is called - so, in the second call you either get an exception or one of the fields is swallowed.BigInteger
. Increment is already done byencodeBigDecimal
.