Re: JSON format for ProtocolBuffers

2008-10-27 Thread Marc Gravell

I would have thought that there was a reflection-based json serializer
for java? A quick search yields JSON-RPC, but I'm not a java bod, so
I have no idea if this is any good.

Sticking to protocol buffers: not for java, but protobuf-net classes
(for .NET) are compatible with DataContractSerializer and friends,
including DataContractJsonSerializer - so by using the same data class
with different serializers when reading/writing (i.e. read with pb,
write with json) you can translate in either direction.

The classes can also be used with xml (XmlSerializer) and Microsoft's
own binary format (BinaryFormatter).

It isn't quite persistance ignorance (as typically attributes are
required), but it is quite close.

Marc
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Protocol Buffers group.
To post to this group, send email to protobuf@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/protobuf?hl=en
-~--~~~~--~~--~--~---



Re: JSON format for ProtocolBuffers

2008-10-27 Thread Kenton Varda
It would be pretty easy to write code that serializes or parses java
protocol message objects in JSON format using the protobuf reflection
interface (see the Message and Builder interfaces).  I don't know of any
existing implementations, though.

On Sun, Oct 26, 2008 at 2:11 PM, Richard [EMAIL PROTECTED] wrote:


 Hi,

 Does anyone have JsonFormat class for ProtocolBuffers in Java? Why
 would this be useful? It would mean that that you could make rpc calls
 from javascript to your web service that you implemented using
 protocol buffers and jetty.

 As an example lets say you have a message with type:

 message Person {
  required string name = 1;
  repeated string phoneNumber = 2;
 }

 Examples of this message in Json are:

 { name: Richard }
 { name: Richard, phone: [ 555-555-111 ] }

 See that repeated fields become lists. That repeated fields don't have
 to be present if they're empty. The Json format doesn't have field
 numbers. Our purpose is not to make the Json messages compact, it is
 to make it easy to use them from javascript.

 Embedded message work as you would expect:

 message Person {
  required string name = 1;
  repeated string phoneNumber = 2;
  repeated Address address = 3;
 }

 message Address {
  required string addrLine1 = 1;
  optional string addrLine2 = 2;
  required string state   = 3;
 }

 Then the Json is

 { name: Richard, phoneNumber: [ 555-555-555 ], address:
 { addrLine1 = 12 Somestreet, state = ZZ } }

 regards,

 Richard.


 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Protocol Buffers group.
To post to this group, send email to protobuf@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/protobuf?hl=en
-~--~~~~--~~--~--~---



JSON format for ProtocolBuffers

2008-10-26 Thread Richard

Hi,

Does anyone have JsonFormat class for ProtocolBuffers in Java? Why
would this be useful? It would mean that that you could make rpc calls
from javascript to your web service that you implemented using
protocol buffers and jetty.

As an example lets say you have a message with type:

message Person {
  required string name = 1;
  repeated string phoneNumber = 2;
}

Examples of this message in Json are:

{ name: Richard }
{ name: Richard, phone: [ 555-555-111 ] }

See that repeated fields become lists. That repeated fields don't have
to be present if they're empty. The Json format doesn't have field
numbers. Our purpose is not to make the Json messages compact, it is
to make it easy to use them from javascript.

Embedded message work as you would expect:

message Person {
  required string name = 1;
  repeated string phoneNumber = 2;
  repeated Address address = 3;
}

message Address {
  required string addrLine1 = 1;
  optional string addrLine2 = 2;
  required string state   = 3;
}

Then the Json is

{ name: Richard, phoneNumber: [ 555-555-555 ], address:
{ addrLine1 = 12 Somestreet, state = ZZ } }

regards,

Richard.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Protocol Buffers group.
To post to this group, send email to protobuf@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/protobuf?hl=en
-~--~~~~--~~--~--~---