private static Gson getGson ( ) { if ( gson == null ) { // Creates the Gson object which will manage the information // received GsonBuilder builder = new GsonBuilder ( ) ; // Serializes enums as lower-case. builder . registerTypeHierarchyAdapter ( Enum . class , new EnumLowercaseSerializer ( ) ) ; // Serializes calendar in format YYYY-MM-DDThh:mm. builder . registerTypeHierarchyAdapter ( Calendar . class , new CalendarSerializer ( ) ) ; // Deserializes payloads from interface. builder . registerTypeAdapter ( Attachment . class , new AttachmentDeserializer ( ) ) ; // Serializes/deserializes buttons from interface. builder . registerTypeAdapter ( Button . class , new ButtonSerializer ( ) ) ; // Deserializes incoming messages from interface. builder . registerTypeAdapter ( IncomingMessage . class , new IncomingMessageDeserializer ( ) ) ; // Deserializes timestamp as Calendar. builder . registerTypeAdapter ( Calendar . class , new CalendarFromTimestampJsonDeserializer ( ) ) ; gson = builder . create ( ) ; } return gson ; }
Initializes the current Gson object if null and returns it . The Gson object has custom adapters to manage datatypes according to Facebook formats .