Qian Zhang commented on MESOS-8656:

commit 499afcc00c0510bfa42d641358604c7bf59e3e13
Author: Qian Zhang <zhq527...@gmail.com\>
Date: Sun Mar 11 21:11:24 2018 +0800

Converted \`JSON::String\` to bool and numbers.
 Previsouly when converting a JSON to a protobuf message in stout, we
 cannot handle the fields like below which are actually valid.
 "int32": "-2147483647"
 "int64": "-9223372036854775807"
 "float": "1.5"
 "bool": "true"
 The conversion will fail with an error like "Not expecting a JSON string
 for field 'int32'".
 So in this patch, \`Try<Nothing> operator()(const JSON::String& string)\`
 was enhanced to be able to convert \`JSON::String\` to bool and numbers.
 This is to match Google's json -> protobuf behavior, see the doc below
 for details:
 Review: [https://reviews.apache.org/r/66025]


commit 61e77658ad1fc9eb72f1b0fa26c4c3257e265fbb
Author: Qian Zhang 
Date: Mon Mar 12 09:15:10 2018 +0800

Updated `ProtobufTest.JSON` for parsing JSON::String to bools & numbers.
 Review: https://reviews.apache.org/r/66026

> Improve stout JSON -> protobuf message conversion to handle more valid JSONs
> ----------------------------------------------------------------------------
>                 Key: MESOS-8656
>                 URL: https://issues.apache.org/jira/browse/MESOS-8656
>             Project: Mesos
>          Issue Type: Improvement
>            Reporter: Qian Zhang
>            Assignee: Qian Zhang
>            Priority: Major
>             Fix For: 1.6.0
> The followings are valid in JSON which can be successfully parsed by Google's 
> protobuf utility function {{JsonStringToMessage()}} but can NOT be parsed our 
> stout, i.e., call {{JSON::parse()}} to convert the JSON to a stout JSON 
> object and then call {{protobuf::parse()}} to parse the JSON object to a 
> protobuf message.
> {code:java}
> "int32": "-2147483647"
> "int64": "-9223372036854775807"
> "bool": "true"
> {code}
> The second step ({{protobuf::parse()}}) will fail with an error like this:
> {code:java}
> Not expecting a JSON string for field 'int32'
> {code}
> This error comes from {{Try<Nothing> operator()(const JSON::String& string)}} 
> which currently can only convert {{JSON::String}} to protobuf 
> string/bytes/enum, so we need to enhance it to be able to convert 
> {{JSON::String}} to bools and integers.
> What we can parse currently are:
> {code:java}
> "int32": -2147483647
> "int64": -9223372036854775807
> "bool": true{code}
> We should make the behavior of our stout JSON -> protobuf conversion 
> consistent with Google's.

This message was sent by Atlassian JIRA

Reply via email to