[
https://issues.apache.org/jira/browse/AVRO-2032?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16501549#comment-16501549
]
Nandor Kollar commented on AVRO-2032:
-------------------------------------
[~zolyfarkas] would you mind creating a pull request from the commit in your
fork? Or if you don't have time for it, I can make one based on your
suggestion, if you don't mind. Though the [JSON
spec|https://tools.ietf.org/html/rfc7159] says that "Numeric values that cannot
be represented in the grammar below (such as Infinity and NaN) are not
permitted.", I'd expect that changing the encoding of an Avro file from binary
to Json shouldn't restrict the users in this case, therefore trying to parse
the token as double makes sense for me.
> Unable to decode JSON-encoded Double.NaN, Double.POSITIVE_INFINITY or
> Double.NEGATIVE_INFINITY
> ----------------------------------------------------------------------------------------------
>
> Key: AVRO-2032
> URL: https://issues.apache.org/jira/browse/AVRO-2032
> Project: Avro
> Issue Type: Bug
> Components: java
> Affects Versions: 1.8.1
> Reporter: Pieter Dekinder
> Priority: Major
>
> When using the JsonEncoder to serialize Double.NaN, Double.POSITIVE_INFINITY
> or Double.NEGATIVE_INFINITY to resulting JSON cannot be parsed by the
> JsonDencoder.
> An AvroTypeException is thrown with the message "Expected double. Got
> VALUE_STRING".
> When using BinaryEncoder/BinaryDecoder, it works fine.
> This JUnit code snippet will reproduce the issue:
> @Test
> public void test() throws Exception {
> Schema schema = SchemaBuilder.builder()
> .record("record")
> .fields()
> .optionalDouble("number1")
> .optionalDouble("number2")
> .optionalDouble("number3")
> .endRecord();
> GenericData.Record record = new GenericData.Record(schema);
> record.put("number1", Double.NaN);
> record.put("number2", Double.POSITIVE_INFINITY);
> record.put("number3", Double.NEGATIVE_INFINITY);
> ByteArrayOutputStream out = new ByteArrayOutputStream();
> JsonEncoder encoder = EncoderFactory.get().jsonEncoder(schema, out);
> new GenericDatumWriter<GenericRecord>(schema).write(record, encoder);
> encoder.flush();
> System.out.println(out);
> Decoder decoder = DecoderFactory.get().jsonDecoder(schema,
> out.toString());
> GenericData.Record deserialized = new GenericData.Record(schema);
> new GenericDatumReader<GenericRecord>(schema).read(deserialized,
> decoder);
> }
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)