I have been looking into ways in which the JsonFormat class can be used to 
create a TypeAdapter<Message> that can be registered with Gson. Writing out 
a Message object to JSON is not an issue but parsing a JSON into Message 
object is a challenge as Gson TypeAdapter's read method gives you a 
JsonReader as input. 

Internally, JsonFormat's merge method creates a JsonReader from 
java.io.Reader, so if a merge method can take a JsonReader as input, then 
it should be possible to create an appropriate TypeAdapter that can be 
registered with Gson.

Would it make sense to introduce a merge() method on JsonFormat that takes 
a JsonReader. Something like 

public void merge(JsonReader json, Message.Builder builder);


Please let me know what you think.


On Monday, September 21, 2015 at 4:20:35 PM UTC-7, Feng Xiao wrote:
>
>
>
> On Mon, Sep 21, 2015 at 3:37 PM, Siddharth Chhabra <[email protected] 
> <javascript:>> wrote:
>
>> Quick question about the json support 
>> 1. Will we get json support if we mix proto2 and proto3 syntax ? is that 
>> supported ?
>>
> You can mix that only in a sub-set of the languages (languages with proto2 
> support: C++, Java, Python and Go). When converted to JSON, proto2-only 
> features like extensions will be ignored completely.
>  
>
>> 2. Since we are using extensions in proto2, can that be used as a member 
>> field  in a proto3 syntax file ?
>>
> Not sure what you mean. You can import proto2 files in proto3 syntax files 
> (again, only work when compiled into languages with proto2 support) and 
> declare the type of a proto3 field to be a proto2 message, but you can not 
> extend a proto3 message or declare an extension to a proto2 message in a 
> proto3 syntax file.
>  
>
>>
>> Please let us know. 
>>
>> On Fri, Sep 11, 2015 at 5:35 PM, Feng Xiao <[email protected] 
>> <javascript:>> wrote:
>>
>>>
>>>
>>> On Fri, Sep 11, 2015 at 5:23 PM, Siddharth Chhabra <
>>> [email protected] <javascript:>> wrote:
>>>
>>>> Was this added ?
>>>> I cant find the JsonFormat class in the api referenc
>>>> The JsonFormat class was mentioned in the thread "Will protobuf support 
>>>> JSON?"
>>>>
>>>> The api is here : 
>>>> https://developers.google.com/protocol-buffers/docs/reference/java/index
>>>> We are thinking of upgrading to protobuf 3 and want to make sure json 
>>>> support is there since otherwise we dont have a need to upgrade.
>>>>
>>> Sorry, the Java doc hasn't been updated yet. You can find the JsonFormat 
>>> class here:
>>>
>>> https://github.com/google/protobuf/blob/master/java/util/src/main/java/com/google/protobuf/util/JsonFormat.java
>>>
>>>  
>>>
>>>>
>>>> Please let us know
>>>> Thanks
>>>>
>>>> -- 
>>>> You received this message because you are subscribed to the Google 
>>>> Groups "Protocol Buffers" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send 
>>>> an email to [email protected] <javascript:>.
>>>> To post to this group, send email to [email protected] 
>>>> <javascript:>.
>>>> Visit this group at http://groups.google.com/group/protobuf.
>>>> For more options, visit https://groups.google.com/d/optout.
>>>>
>>>
>>>
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.

Reply via email to