[ 
https://issues.apache.org/jira/browse/AVRO-2032?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18044263#comment-18044263
 ] 

ASF subversion and git services commented on AVRO-2032:
-------------------------------------------------------

Commit 8a22cef7fb532fa202e2175040f082d43c8e07c1 in avro's branch 
refs/heads/dependabot/npm_and_yarn/lang/js/nyc-17.1.0 from Raphael Rösch
[ https://gitbox.apache.org/repos/asf?p=avro.git;h=8a22cef7fb ]

AVRO-2032: Add support for NaN, Infinity and -Infinity in JsonDecoder (#3066)

JsonEncoder uses special string values to represent NaN, Infinity and
-Infinity values for float and double values, but JsonDecoder does not
accept these string values. This change adds support for these special
values to JsonDecoder.

> 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: Apache Avro
>          Issue Type: Bug
>          Components: java
>    Affects Versions: 1.8.1
>            Reporter: Pieter Dekinder
>            Priority: Major
>              Labels: pull-request-available
>             Fix For: 1.11.5, 1.12.2
>
>          Time Spent: 3h 20m
>  Remaining Estimate: 0h
>
> 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:
> {code}
>     @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);
>     }
> {code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to