How to handle a NumberFormatException with Gson in deserialization a JSON response
Here is an example that I made for Long type. This is a better option: public class LongTypeAdapter extends TypeAdapter<Long> { @Override public Long read(JsonReader reader) throws IOException { if (reader.peek() == JsonToken.NULL) { reader.nextNull(); return null; } String stringValue = reader.nextString(); try { Long value = Long.valueOf(stringValue); return value; } catch (NumberFormatException e) { … Read more