List of usage examples for com.google.gson GsonBuilder create
public Gson create()
From source file:com.ericsson.jira.oslc.resources.JiraChangeRequest.java
License:Open Source License
/** * Converts data class of Application link to GSON format * @param the list of Application links * @return Application links in GSON format *//*from ww w. ja v a 2s .c o m*/ public static String parseOSLCLinks(final List<AppLink> appLinkList) { // prepare GSON GsonBuilder gsonBuilder = new GsonBuilder(); Gson gson = gsonBuilder.create(); AppLinksRepository appLinkRepository = new AppLinksRepository(); // return empty string to save empty content to customfield if (appLinkList.isEmpty()) { return ""; } for (AppLink appLink : appLinkList) { appLinkRepository.addAppLink(appLink, true); } String jsonAppLinks = gson.toJson(appLinkRepository); if (jsonAppLinks == null) { jsonAppLinks = ""; } return jsonAppLinks; }
From source file:com.example.mvpexample.dagger.ApplicationModule.java
License:Open Source License
@Singleton @Provides public Gson providesGson(GsonBuilder builder) { return builder.create(); }
From source file:com.example.repository_pattern_demo.di.HttpModule.java
License:Apache License
@Provides @Singleton// w w w . ja v a2 s . c o m Gson providesGson() { GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.registerTypeAdapterFactory(TypeAdapterFactoryImpl.create()); gsonBuilder.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES); return gsonBuilder.create(); }
From source file:com.expensify.testframework.GetNextCommandResultContainer.java
License:Microsoft Public License
public static CommandBase parse(String json) { GsonBuilder gsonBuilder = new GsonBuilder(); CommandDeserializer deserializer = new CommandDeserializer(); deserializer.registerCommonCommands(); gsonBuilder.registerTypeAdapter(CommandBase.class, deserializer); Gson gson = gsonBuilder.create(); GetNextCommandResultContainer commandContainer = gson.fromJson(json, GetNextCommandResultContainer.class); return commandContainer.GetNextCommandResult; }
From source file:com.expensify.testframework.RawSubmitResultContainer.java
License:Microsoft Public License
public static String WrapAndStringify(ResultBase result) { RawSubmitResultContainer toSubmit = new RawSubmitResultContainer(); toSubmit.jsonResult = RawStringify(result); GsonBuilder gsonBuilder = new GsonBuilder(); Gson gson = gsonBuilder.create(); return gson.toJson(toSubmit); }
From source file:com.expensify.testframework.RawSubmitResultContainer.java
License:Microsoft Public License
public static String RawStringify(ResultBase result) { GsonBuilder gsonBuilder = new GsonBuilder(); //gsonBuilder.serializeNulls(); //gsonBuilder.setFieldNamingPolicy(FieldNamingPolicy.UPPER_CAMEL_CASE); //gsonBuilder.disableHtmlEscaping(); //gsonBuilder.registerTypeHierarchyAdapter(ResultBase.class, new ResultSerializer()); Gson gson = gsonBuilder.create(); String resultJson = gson.toJson(result); resultJson = hackResultJsonOrder(resultJson); return resultJson; }
From source file:com.expensify.testframework.SubmitResultContainer.java
License:Microsoft Public License
public static String RawStringify(ResultBase result) { GsonBuilder gsonBuilder = new GsonBuilder(); Gson gson = gsonBuilder.create(); gsonBuilder.serializeNulls();/*w w w . j a v a2s. co m*/ gsonBuilder.setFieldNamingPolicy(FieldNamingPolicy.UPPER_CAMEL_CASE); gsonBuilder.disableHtmlEscaping(); gsonBuilder.registerTypeHierarchyAdapter(ResultBase.class, new ResultSerializer()); String resultJson = gson.toJson(result); resultJson = hackResultJsonOrder(resultJson); return resultJson; }
From source file:com.expensify.testframework.utils.CommandDeserializer.java
License:Microsoft Public License
public CommandDeserializer(String commandElementName) { this.commandElementName = commandElementName; GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.setFieldNamingPolicy(FieldNamingPolicy.UPPER_CAMEL_CASE); gson = gsonBuilder.create(); commandRegistry = new HashMap<String, Class<? extends CommandBase>>(); }
From source file:com.facebook.buck.intellij.plugin.ws.buckevents.BuckEventHandler.java
License:Apache License
public BuckEventHandler(BuckEventsQueueInterface queue, Runnable onConnectHandler, Runnable onDisconnectHandler) { mOnConnectHandler = onConnectHandler; mOnDisconnectHandler = onDisconnectHandler; mQueue = queue;/*from w w w . j a v a2 s . c o m*/ GsonBuilder builder = new GsonBuilder(); builder.registerTypeAdapter(BuckEventInterface.class, new BuckEventAdapter()); mGson = builder.create(); }
From source file:com.fiftycuatro.providers.GsonProvider.java
License:Apache License
/** * Hereby one will register every subtypes to be supported by Gson. *//*from w w w . jav a 2 s . co m*/ private static final Gson registerGsonTypeAdapterFactories() { GsonBuilder builder = new GsonBuilder(); // handle double NaN builder.serializeSpecialFloatingPointValues(); // register subtypes // builder.registerTypeAdapterFactory(RuntimeTypeAdapterFactory // .of(Object.class).registerSubtype(SubObjecOne.class) // .registerSubtype(SubObjecTwo.class) // .registerSubtype(SubObjecThree.class)); return builder.create(); }