Open aguibert opened 4 years ago
Hi @aguibert,
Why not just requiring to respect the json grammar (something along https://www.json.org/)?
both documents point to the same allowed grammar. Am I missing something?
Yes, the spec pattern to explicitly say what is supported vs letting java specific syntax enabled through format class dependency (can't depend on the locale here for instance). So my 2cts were to phrase it as respecting the rfc you quoted rather than using a java reference.
How Jackson and other projects like Gson and Genson and dealing with it?
As the BigDecimal output is stored as a formatted String in JSON and not a Number (without quotes), maybe we don't have an issue here and the behavior is still correct, also confusing as it is depending on the system default locale when not explicitly set.
Also see my comment in the original ticket here https://github.com/eclipse-ee4j/yasson/issues/319#issuecomment-526816745
@Simulant87 currently it is true that BigDecimal is output as String and numbers are output as non-Strings, but this difference in type based on number value also causes issues. We will be revising this in https://github.com/eclipse-ee4j/jsonb-api/issues/187 so that we always output as non-Strings
@aguibert Latest JSON RFC is https://tools.ietf.org/rfc/rfc8259.txt :) But grammar definition was not changed. ... I personally don't like an idea of storing JSON number as String, even BigDecimal. RFC section 6 (Numbers) does not define any limits for number size/precission - they are optional (e.g. IEEE 754) - so JSON-B spec/API can define number storage of any size/precission as JSON number. -> #187
I would expect that serialization will always produce RFC 8259 compliant JSON number and things like @JsonbNumberFormat domehow do not fit into this. But OK, if there is some strong enough bussiness requirement, things like this may happen. But they must be always explicitly configured for specific document or field.
On the other hand de-serialization may be a bit foolproof and may properly parse even some invalid formats, like ,
instead of . when parsing number from JSON string
.
Also, while I'm currently working on https://github.com/eclipse-ee4j/yasson/issues/335, I was implementing JSON number deserializer there. And as a result, I would like to make some changes in the spec:
Currently the
@JsonbNumberFormat
annotation supports any NumberFormat that can be specified by ajava.text.NumberFormat
. However, all of the NumberFormats that can be specified in Java are not also valid JSON.This came up in this Yasson issue where a user pointed out commas are used as the decimal separator in some locales, which is not valid JSON.
See RFC 7156 section 6:
Proposed solution:
Require that implementations impose extra limitations on the patterns that can be specified in a NumberFormat string, namely blocking characters that are not listed in RFC 7159 section 6, such as the comma.