HectorLealR / directjngine

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

Failed parsing JSON source #1

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. ui have a TextArea
2. string have \n
3. com.google.gson.JsonParseException: Failed parsing JSON source:
java.io.StringReader@1298826 to Json

parse ok
Extjs php example(change textfiled to textarea) will work ok,
buy jng throw exception.

Caused by: com.google.gson.ParseException: Encountered "\"" at line 1,
column 2.

maybe dobule quoted?

Original issue reported on code.google.com by lxb...@gmail.com on 9 Sep 2009 at 8:42

GoogleCodeExporter commented 8 years ago
after some test i found reason:
gson do not have method convert JsonElement to JSONString;

JsonElement.toString() not proccess \n \t .... special chars

my solution:

patch google-gson-1.3:

public void toJson(Object src, Type typeOfSrc, Appendable writer) {
    try {
      if (src != null) {
        JsonSerializationContext context = new JsonSerializationContextDefault(
            createDefaultObjectNavigatorFactory(), serializeNulls, serializers);
        JsonElement jsonElement = null;
        if(src instanceof JsonElement){
            jsonElement = (JsonElement)src;
        }else{
            jsonElement = context.serialize(src, typeOfSrc);
        }
....

patch jngine:

public class JsonRequestProcessor extends RequestProcessorBase

where: a instance JsonElement call toString()

change to getGson.toJson(JsonElement)

Original comment by lxb...@gmail.com on 9 Sep 2009 at 12:02