Closed GoogleCodeExporter closed 9 years ago
Can you address this with the streaming API?
http://sites.google.com/site/gson/streaming
Original comment by limpbizkit
on 21 Mar 2011 at 9:20
Following is my similar case which I need to do by implementing JsonElement and
couldn't figure out how to do with streaming API. Any idea please?
Gson gson = new GsonBuilder()
.registerTypeAdapter(MyRawJson.class, new MyRawJsonSerializer())
.create();
interface MyRawJson {
String getJson();
}
class MyRawJsonSerializer implements JsonSerializer<RawJson> {
@Override
public JsonElement serialize(final MyRawJson src, Type type, JsonSerializationContext ctx) {
return new JsonElement() {
@Override
protected void toString(Appendable sb, Escaper escaper) throws IOException {
sb.append(src.getJson());
}
};
}
}
Original comment by ali.sak...@gmail.com
on 15 Jul 2011 at 10:30
You're close. Use JsonParser to convert your JSON string to a JSON element, and
then return that in your serialize() method.
Original comment by limpbizkit
on 17 Jul 2011 at 4:44
How to do this in the current gson version? I see in 2.2.2 the escaper class is
gone and instead you use the JsonWriter..
I'm trying to extend JsonElement to have an implementation that avoids
escaping a string which is already escaped (performance wise, not going through
each and every character).
Original comment by anmolsha...@gmail.com
on 18 Mar 2013 at 5:44
Original issue reported on code.google.com by
jbros...@gmail.com
on 21 Sep 2010 at 3:58