@@ -131,13 +131,21 @@ where the Avro Schema is known to the decoding party.
131
131
132
132
The features are designed to be orthogonal and can be implemented separately.
133
133
134
- - [ 1: Alternate names] ( #feature-1-alternate-names )
135
- - [ 2: Avro ` binary ` and ` fixed ` type data encoding] ( #feature-2-avro-binary-and-fixed-type-data-encoding )
136
- - [ 3: Avro ` decimal ` logical type data encoding] ( #feature-3-avro-decimal-logical-type-data-encoding )
137
- - [ 4: Avro time, date, and duration logical types] ( #feature-4-avro-time-date-and-duration-logical-types )
138
- - [ 5: Handling unions with primitive type values and enum values] ( #feature-5-handling-unions-with-primitive-type-values-and-enum-values )
139
- - [ 6: Handling unions of record values and of maps] ( #feature-6-handling-unions-of-record-values-and-of-maps )
140
- - [ 7: Document root records] ( #feature-7-document-root-records )
134
+ - [ "Plain JSON" encoding for Apache Avro] ( #plain-json-encoding-for-apache-avro )
135
+ - [ Notational Conventions] ( #notational-conventions )
136
+ - [ Interoperability issues of the Avro JSON Encoding with common JSON usage] ( #interoperability-issues-of-the-avro-json-encoding-with-common-json-usage )
137
+ - [ The Plain JSON encoding] ( #the-plain-json-encoding )
138
+ - [ Feature 1: Alternate names] ( #feature-1-alternate-names )
139
+ - [ ` altnames ` map] ( #altnames-map )
140
+ - [ ` altsymbols ` map] ( #altsymbols-map )
141
+ - [ Feature 2: Avro ` binary ` and ` fixed ` type data encoding] ( #feature-2-avro-binary-and-fixed-type-data-encoding )
142
+ - [ Feature 3: Avro ` decimal ` logical type and ` long ` type data encodings] ( #feature-3-avro-decimal-logical-type-and-long-type-data-encodings )
143
+ - [ Feature 4: Avro time, date, and duration logical types] ( #feature-4-avro-time-date-and-duration-logical-types )
144
+ - [ Feature 5: Handling unions with primitive type values and enum values] ( #feature-5-handling-unions-with-primitive-type-values-and-enum-values )
145
+ - [ Feature 6: Handling unions of record values and of maps] ( #feature-6-handling-unions-of-record-values-and-of-maps )
146
+ - [ Type structure matching] ( #type-structure-matching )
147
+ - [ Discriminator property] ( #discriminator-property )
148
+ - [ Feature 7: Document root records] ( #feature-7-document-root-records )
141
149
142
150
Features 2, 3, 4, and 5 are trivial on all platforms and frameworks that handle
143
151
JSON. Features 1 and 7 are hints for the JSON encoder and decoder to be able to
@@ -281,11 +289,25 @@ When encoding data typed with the Avro `binary` or `fixed` types, the byte
281
289
sequence is encoded into and from Base64 encoded string values, conforming with
282
290
IETF RFC4648, Section 4.
283
291
284
- ### Feature 3: Avro ` decimal ` logical type data encoding
292
+ ### Feature 3: Avro ` decimal ` logical type and ` long ` type data encodings
285
293
286
- When encoding data typed with the Avro logical ` decimal ` type, the numeric
287
- value is encoded into a from a JSON ` number ` value. JSON numbers are represented
288
- as text and do not lose precision as IEEE754 floating points do.
294
+ When encoding data typed with the Avro logical ` decimal ` type or a ` long ` type,
295
+ the numeric value is encoded into a JSON ` string ` value using the JSON number
296
+ syntax defined in RFC8259, Section 6.
297
+
298
+ RFC8259, Section 6 explicitly allows implementations to back the JSON number
299
+ type with an IEEE754 double precision floating point type, even though the JSON
300
+ syntax does not limit precision.
301
+
302
+ For ` decimal ` that means that JSON number values are not guaranteed to be able
303
+ to represent the range of Avro decimal values. Worse, IEEE 754 cannot represent
304
+ decimal values exactly (0.1 for instance), which causes precision issues in
305
+ monetary calculations.
306
+
307
+ Integer values that are outside the range of IEEE754 double precision floating
308
+ point values are not guaranteed to be representable. The range of representable
309
+ integers is -2^53 to 2^53. The required range for an Avro ` long ` type is -2^63
310
+ to 2^63-1.
289
311
290
312
When using a JSON library to implement the encoding, decimal values MUST NOT be
291
313
converted through an IEEE floating point type (e.g. double or float in most
@@ -341,7 +363,7 @@ types for the plain JSON encoding.
341
363
| ------------ | --------- | ----------------------------------------------------------------------------------- |
342
364
| null | null | The field MAY be omitted |
343
365
| boolean | boolean | |
344
- | int,long | integer | |
366
+ | int | integer | |
345
367
| float,double | number | |
346
368
| bytes | string | Base64 string, see [ Feature 2] ( #feature-2-avro-binary-and-fixed-type-data-encoding ) |
347
369
| string | string | |
@@ -352,7 +374,7 @@ types for the plain JSON encoding.
352
374
| fixed | string | Base64 string, see [ Feature 2] ( #feature-2-avro-binary-and-fixed-type-data-encoding ) |
353
375
| date/time | string | See [ Feature 4] ( #feature-4-avro-time-date-and-duration-logical-types ) |
354
376
| UUID | string | |
355
- | decimal | number | See [ Feature 3] ( #feature-3-avro-decimal-logical-type-data-encoding ) |
377
+ | decimal, long | string | See [ Feature 3] ( #feature-3-avro-decimal-logical-type-data-encoding ) |
356
378
357
379
### Feature 6: Handling unions of record values and of maps
358
380
0 commit comments