You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avro.apache.org by "Thiruvalluvan M. G. (JIRA)" <ji...@apache.org> on 2013/06/11 21:28:21 UTC

[jira] [Commented] (AVRO-1290) AvroCpp json text backend produces "inf" for double values of infinity but won't consume them

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

Thiruvalluvan M. G. commented on AVRO-1290:
-------------------------------------------

JSON specification does not say how to encode +infinity, -infinity or NaN. Consequently other language bindings of Avro do not honor infinity etc.

Interestingly, Jackson, a popular Java JSON library, encodes +infinity, -infinity and Nan as strings "Infinity", "-Infinity" and "NaN" respectively. It is also able to decode them properly back to appropriate data. Ruby's string conversion of these are exactly the same as Jackson convention. However, Ruby's to_json method that comes with the language runtime refuses to encode +infinity, -infinity or NaN. Apparently PHP does something very different: http://stackoverflow.com/questions/13581843/php-how-to-encode-infinity-or-nan-numbers-to-json

We can do either of the following:

1. Throw an exception if we encounter +infinity, -infinity or NaN while encoding into JSON. (Ruby behavior)
2. Stick to Jackson/Ruby convention. This is better than inventing a new convention of our own.

My personal preference is for (1), because that conforms to JSON standard. But if others think (2) is better, we can go with it as well.

If we go with option (2), the format for serialization would be as follows. Let's say we have an object with a single double field "d" in it. Examples of encoded JSON are:

{ "d": 1.45 }
{ "d": "Infinity" }
{ "d": "-Infinity" }
{ "d": "NaN" }

Please note that the double is encoded a string if it is one of the special values.

                
> AvroCpp json text backend produces "inf" for double values of infinity but won't consume them
> ---------------------------------------------------------------------------------------------
>
>                 Key: AVRO-1290
>                 URL: https://issues.apache.org/jira/browse/AVRO-1290
>             Project: Avro
>          Issue Type: Bug
>          Components: c++
>    Affects Versions: 1.7.3
>            Reporter: Daniel Russel
>         Attachments: patch
>
>
> If you use the json encoder and pass it a double with value e.g. std::numeric_limits<double>::infinity() it happily writes the literal "inf". However, the decoder chokes on that literal.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira