List of usage examples for com.google.gson GsonBuilder GsonBuilder
public GsonBuilder()
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 w w w .ja v a 2s . 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./*www . j av a 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.kik.util.json.IncomingMessagesDeserializer.java
License:Open Source License
/** * Instantiates a new AttachmentDeserializer. */// w w w .j a v a2s . c o m public IncomingMessagesDeserializer() { GsonBuilder builder = new GsonBuilder(); builder.addDeserializationExclusionStrategy(new SkipDeserializationAnnotationExclusionStrategy()); delegateGson = builder.create(); }
From source file:co.aurasphere.botmill.kik.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 ww .j a v a2s . 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.registerTypeHierarchyAdapter(MessageCallback.class, new IncomingMessagesDeserializer()); // EnumDeserializer builder.registerTypeHierarchyAdapter(Calendar.class, new CalendarSerializer()); gson = builder.create(); } return gson; }
From source file:co.aurasphere.botmill.skype.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 av a2 s . c om*/ * * @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.registerTypeHierarchyAdapter(Calendar.class, new CalendarSerializer()); gson = builder.create(); } return gson; }
From source file:co.aurasphere.botmill.telegram.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 Telegram * formats./* w w w . ja v a 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 CalendarFromTimestampJsonDeserializer()); 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./*from w w w . ja v a 2s . c o 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.common.conf.ArtifactConfigReader.java
License:Apache License
public ArtifactConfigReader() { this.gsonCache = CacheBuilder.newBuilder().build(new CacheLoader<Id.Namespace, Gson>() { @Override// w w w . j av a2 s. com public Gson load(Id.Namespace namespace) throws Exception { return new GsonBuilder() .registerTypeAdapter(ArtifactRange.class, new ArtifactRangeDeserializer(namespace)) .registerTypeAdapter(ArtifactConfig.class, new ArtifactConfigDeserializer()) .registerTypeAdapter(PluginClass.class, new PluginClassDeserializer()).create(); } }); }
From source file:co.cask.cdap.common.conf.ConfigurationJsonTool.java
License:Apache License
public static void exportToJson(Configuration configuration, Appendable output) { Map<String, String> map = Maps.newHashMapWithExpectedSize(configuration.size()); for (Map.Entry<String, String> entry : configuration) { map.put(entry.getKey(), entry.getValue()); }/*w w w. j a va2s . c o m*/ new GsonBuilder().setPrettyPrinting().create().toJson(map, output); }
From source file:co.cask.cdap.gateway.handlers.AppFabricHttpHandler.java
License:Apache License
@Nullable private SessionInfo retrieve(String accountId) { try {/*from ww w . jav a2 s .c o m*/ final Location outputDir = locationFactory.create(archiveDir + "/" + accountId); if (!outputDir.exists()) { return null; } final Location sessionInfoFile = outputDir.append("session.json"); InputSupplier<Reader> reader = new InputSupplier<Reader>() { @Override public Reader getInput() throws IOException { return new InputStreamReader(sessionInfoFile.getInputStream(), "UTF-8"); } }; Gson gson = new GsonBuilder().registerTypeAdapter(Location.class, new LocationCodec(locationFactory)) .create(); Reader r = reader.getInput(); try { return gson.fromJson(r, SessionInfo.class); } finally { Closeables.closeQuietly(r); } } catch (IOException e) { LOG.warn("Failed to retrieve session info for account."); } return null; }