discomarathon / google-gson

Automatically exported from code.google.com/p/google-gson
0 stars 0 forks source link

How to serialize single-level simple arrays #159

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I've currently used net.sf.json and flexjson and was hoping google-gson 
was as easy to use. Is it really necessary to write a custom serializer to 
output a simple JsonArry as follows?

[{"xxx","yyy","zzz"},{"111","222","333"}]

What am I missing...a code snippet would be appreciated. 

Original issue reported on code.google.com by quin.h.m...@boeing.com on 24 Sep 2009 at 6:33

GoogleCodeExporter commented 9 years ago
This is not a bug, please post such comments on the Gson discussion group where 
they can be answered 
best. The discussion group is at: http://groups.google.com/group/google-gson 

Please move any further response to the group after cutting and pasting from 
this issue. Thanks.

It is not clear to me what you are outputting from? Is it an Array (or 
collection) of objects? If so, Gson can 
easily convert it to what you want. No need to write a custom serializer.

Class Element {
  String a, b, c;
}

Element[] array = new Element[] { new Element("xxx", "yyy", "zzz"}, new 
Element("111", "222", "333"); };

Gson.toJson(array); will output what you want.

Original comment by inder123 on 24 Sep 2009 at 9:11