List of usage examples for com.google.gson GsonBuilder registerTypeAdapter
@SuppressWarnings({ "unchecked", "rawtypes" }) public GsonBuilder registerTypeAdapter(Type type, Object typeAdapter)
From source file:co.aurasphere.botmill.fb.internal.util.json.FbBotMillJsonUtils.java
License:Open Source License
/** * Initializes the current Gson object if null and returns it. The Gson * object has custom adapters to manage datatypes according to Facebook * formats./*from www .j a va2 s.co m*/ * * @return the current instance of Gson. */ 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; }
From source file:co.aurasphere.botmill.fb.internal.util.json.JsonUtils.java
License:Open Source License
/** * Initializes the current Gson object if null and returns it. The Gson * object has custom adapters to manage datatypes according to Facebook * formats./*from w w w .j a va 2 s.c o m*/ * * @return the current instance of Gson. */ 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()); // Deserializes buttons from interface. builder.registerTypeAdapter(Button.class, new ButtonDeserializer()); builder.registerTypeAdapter(List.class, new PolimorphicalListSerializer<List<Button>>()); // Deserializes incoming messages from interface. builder.registerTypeAdapter(IncomingMessage.class, new IncomingMessageDeserializer()); gson = builder.create(); } return gson; }
From source file:co.aurasphere.botmill.util.JsonUtils.java
License:Open Source License
/** * Initializes the current Gson object if null and returns it. The Gson * object has custom adapters to manage datatypes according to Facebook * formats./* w ww . jav a 2s. co m*/ * * @return the current instance of Gson. */ public 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()); builder.registerTypeAdapter(Entity.class, new EntityValueDeserializer()); gson = builder.create(); } return gson; }
From source file:co.cask.cdap.internal.app.ApplicationSpecificationAdapter.java
License:Apache License
public static GsonBuilder addTypeAdapters(GsonBuilder builder) { return builder.registerTypeAdapter(Schema.class, new SchemaTypeAdapter()) .registerTypeAdapter(ApplicationSpecification.class, new ApplicationSpecificationCodec()) .registerTypeAdapter(FlowSpecification.class, new FlowSpecificationCodec()) .registerTypeAdapter(FlowletSpecification.class, new FlowletSpecificationCodec()) .registerTypeAdapter(MapReduceSpecification.class, new MapReduceSpecificationCodec()) .registerTypeAdapter(SparkSpecification.class, new SparkSpecificationCodec()) .registerTypeAdapter(WorkflowSpecification.class, new WorkflowSpecificationCodec()) .registerTypeAdapter(WorkflowNode.class, new WorkflowNodeCodec()) .registerTypeAdapter(WorkflowActionSpecification.class, new WorkflowActionSpecificationCodec()) .registerTypeAdapter(ScheduleSpecification.class, new ScheduleSpecificationCodec()) .registerTypeAdapter(ServiceSpecification.class, new ServiceSpecificationCodec()) .registerTypeAdapter(WorkerSpecification.class, new WorkerSpecificationCodec()) .registerTypeAdapter(WorkflowNodeThrowable.class, new WorkflowNodeThrowableCodec()) .registerTypeAdapterFactory(new AppSpecTypeAdapterFactory()); }
From source file:co.cask.tigon.internal.app.FlowSpecificationAdapter.java
License:Apache License
public static void addTypeAdapters(GsonBuilder builder) { builder.registerTypeAdapter(Schema.class, new SchemaTypeAdapter()) .registerTypeAdapter(FlowSpecification.class, new FlowSpecificationCodec()) .registerTypeAdapter(FlowletSpecification.class, new FlowletSpecificationCodec()) .registerTypeAdapter(ResourceSpecification.class, new ResourceSpecificationCodec()) .registerTypeAdapterFactory(new AppSpecTypeAdapterFactory()); }
From source file:co.Converters.java
License:Open Source License
/** * Registers the {@link DateMidnight} converter. * @param builder The GSON builder to register the converter with. * @return A reference to {@code builder}. *///w ww .j a va2 s.c o m public static GsonBuilder registerDateMidnight(GsonBuilder builder) { if (builder == null) { throw new NullPointerException("builder cannot be null"); } builder.registerTypeAdapter(DATE_MIDNIGHT_TYPE, new DateMidnightConverter()); return builder; }
From source file:co.Converters.java
License:Open Source License
/** * Registers the {@link DateTime} converter. * @param builder The GSON builder to register the converter with. * @return A reference to {@code builder}. *///from w w w . ja v a2 s . c o m public static GsonBuilder registerDateTime(GsonBuilder builder) { if (builder == null) { throw new NullPointerException("builder cannot be null"); } builder.registerTypeAdapter(DATE_TIME_TYPE, new DateTimeConverter()); return builder; }
From source file:co.Converters.java
License:Open Source License
/** * Registers the {@link LocalDate} converter. * @param builder The GSON builder to register the converter with. * @return A reference to {@code builder}. *///w ww. ja v a 2s. co m public static GsonBuilder registerLocalDate(GsonBuilder builder) { if (builder == null) { throw new NullPointerException("builder cannot be null"); } builder.registerTypeAdapter(LOCAL_DATE_TYPE, new LocalDateConverter()); return builder; }
From source file:co.Converters.java
License:Open Source License
/** * Registers the {@link LocalDateTime} converter. * @param builder The GSON builder to register the converter with. * @return A reference to {@code builder}. *///ww w .j a v a 2s . c o m public static GsonBuilder registerLocalDateTime(GsonBuilder builder) { if (builder == null) { throw new NullPointerException("builder cannot be null"); } builder.registerTypeAdapter(LOCAL_DATE_TIME_TYPE, new LocalDateTimeConverter()); return builder; }
From source file:co.Converters.java
License:Open Source License
/** * Registers the {@link LocalTime} converter. * @param builder The GSON builder to register the converter with. * @return A reference to {@code builder}. *//*w ww .j av a 2s. c o m*/ public static GsonBuilder registerLocalTime(GsonBuilder builder) { if (builder == null) { throw new NullPointerException("builder cannot be null"); } builder.registerTypeAdapter(LOCAL_TIME_TYPE, new LocalTimeConverter()); return builder; }