Gson has some odd behavior when I try to convert a string to json. The code below transforms string draft into json responses. Is there a way to prevent gson from adding the
This work for me.
Step 1: Copy the ObjectTypeAdapter in gson into the project, keeping the path the same as in gson Like this
com
- xxx
- xxx
com
- google
- gson
- internal
- bind
ObjectTypeAdapter
Step 2: Modify ObjectTypeAdapter
case NUMBER:
return in.nextDouble();
Modified to
case NUMBER:
String number = in.nextString();
try {
return Long.valueOf(number);
} catch (NumberFormatException e) {
return Double.valueOf(number);
}
OK. Gson will prioritizes the ObjectTypeAdapter in the project.