List of usage examples for com.google.gson GsonBuilder create
public Gson create()
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 . 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()); // 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./*w w w .j ava 2s . 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. *//*from www . ja va 2s .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 ww w . j ava 2 s . 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.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.//w w w. jav a 2 s .com * * @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./*from ww w . j av a 2 s .c om*/ * * @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 2 s . 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.tigon.internal.app.FlowSpecificationAdapter.java
License:Apache License
public static FlowSpecificationAdapter create(SchemaGenerator generator) { GsonBuilder builder = new GsonBuilder(); addTypeAdapters(builder);/*from w w w . jav a 2s . co m*/ return new FlowSpecificationAdapter(generator, builder.create()); }
From source file:codemate.ui.Config.java
License:Open Source License
/** * load// www . j ava2 s . co m * * This method loads the given configuration. * * @param fileName * * @author Li Dong <dongli@lasg.iap.ac.cn> */ public static void load(String fileName) { if (fileName.equals(defaultConfig)) { File root = new File(defaultRoot); if (!root.exists()) { UI.notice("Config", "There is no runtime directory as" + defaultRoot + "."); boolean succ = (new File(defaultRoot)).mkdir(); if (succ) UI.notice("codemate", "Create one."); else UI.error("codemate", "Couldn't create one!"); } } File file = new File(fileName); if (!file.exists()) { UI.notice("codemate", "Create a configuration as " + fileName + "."); createTemplateConfig(fileName); } else { UI.notice("codemate", "Load configuration from " + fileName + "."); try { GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.registerTypeAdapter(ConfigData.class, new ConfigDataDeserializer()); Gson gson = gsonBuilder.create(); String json = new Scanner(file).useDelimiter("\\Z").next(); configData = gson.fromJson(json, ConfigData.class); } catch (Exception e) { e.printStackTrace(); UI.error("codemate", "Encounter error while loading configuation from " + fileName + "!"); } } // spread configuration to other classes for (Entry<String, BlockData> libraryData : configData.data.get("library").data.entrySet()) { LibraryMate libraryMate = LibraryMates.searchLibrary(libraryData.getKey()); if (libraryMate != null) { libraryMate.setRoot(libraryData.getValue().data.get("root")); libraryMate.setWrapper("Fortran", libraryData.getValue().data.get("fortran_wrapper")); } } }
From source file:com.ab.util.AbJsonUtil.java
License:Apache License
/** * /*from w w w . j a v a2 s . c om*/ * ??json. * @param list * @return */ public static String toJson(Object src) { String json = null; try { GsonBuilder gsonb = new GsonBuilder(); Gson gson = gsonb.create(); json = gson.toJson(src); } catch (Exception e) { e.printStackTrace(); } return json; }