Skip to content

Parse JSON Data using wrapper class, where String’s object/key name is numeric

I am trying to parse a special JSON data using Wrapper class, special means a JSON which have numeric keys as string like below :

"hours":"01-Nov 08:00",

I know how to parse JSON data using wrapper class but this case is special because wrapper class’s object name not accepting the numeric as String.

Wrapper/POJO Class

enter image description here

I don’t want to go with JSON object based parsing. Anyone have any idea about it?



The Gson library has SerializedName functionality in which it parses the corresponding value of the key defined in SerializeName’s parameter. Things will be tougher if your key is a pure integer since Java disallows it as variable name, in this case SerializeName will save you from that headache and it makes your code way more maintainable.

Example usage :

@SerializedName("1011") double lat;
@SerializedName("1022") double lng;