From the answer of Jigar I could deduce a simpler solution for this case of problem.
A very easy way to save the time of mapping every variable is to write a deserializer for the string class and then declare the wanted variable as a string.
public class StringDeserializer implements JsonDeserializer<String> {
@Override
public String deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
return jsonElement.toString();
}
}
While using following POJO:
int a_num;
String an_object;
String a_string;
And finally registering the TypeAdapter:
private static Gson gson = new GsonBuilder()
.registerTypeAdapter(String.class, new StringDeserializer()).create();
With this deserializer it is possible to deserialize any field you want as a string. Just type it to a string in the POJO.
TypeAdapter.