List of usage examples for com.google.gson GsonBuilder create
public Gson create()
From source file:com.ccc.crest.core.cache.crest.war.WarsCollection.java
License:Open Source License
public static Future<EveData> getFuture(CrestResponseCallback callback) throws Exception { GsonBuilder gson = new GsonBuilder(); gson.registerTypeAdapter(WarsCollection.class, new WarsCollection()); //@formatter:off CrestRequestData rdata = new CrestRequestData(null, getUrl(), gson.create(), null, WarsCollection.class, callback, ReadScope, getVersion(VersionType.Get), continueRefresh); //@formatter:on return CrestController.getCrestController().crestClient.getCrest(rdata); }
From source file:com.ccc.crest.core.cache.crest.war.WarsElement.java
License:Open Source License
public static Future<EveData> getFuture(CrestResponseCallback callback) throws Exception { GsonBuilder gson = new GsonBuilder(); gson.registerTypeAdapter(WarsElement.class, new WarsElement()); //@formatter:off CrestRequestData rdata = new CrestRequestData(null, getUrl(), gson.create(), null, WarsElement.class, callback, ReadScope, getVersion(VersionType.Get), continueRefresh); //@formatter:on return CrestController.getCrestController().crestClient.getCrest(rdata); }
From source file:com.ccc.crest.core.client.json.RootJsonGenerator.java
License:Open Source License
public RootJsonGenerator() { String logPath = DefaultLogPath; System.setProperty(LogFilePathKey, logPath); String base = logPath;//from w ww . j av a 2 s . c om int idx = logPath.lastIndexOf('.'); if (idx != -1) base = logPath.substring(0, idx); System.setProperty(LogFileBaseKey, logPath); log = LoggerFactory.getLogger(getClass()); if (log.isDebugEnabled()) { LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory(); // TODO: StatusPrinter.setPrintStream StatusPrinter.print(lc); } if (UseSisi) rootUrl = SisiUrlBase; else rootUrl = TqUrlBase; init(); GsonBuilder gson = new GsonBuilder(); gson.setPrettyPrinting(); json = gson.create().toJson(endpoints); }
From source file:com.claresco.tinman.json.JsonUtility.java
License:Open Source License
/** * /*from ww w . j av a 2 s . c o m*/ * Description: * Building Gson * * Params: * */ public static Gson createGson() { final GsonBuilder gsonBuilder = new GsonBuilder(); //Register to gsonBuilder gsonBuilder.registerTypeAdapter(XapiStatement.class, new XapiStatementJson()); gsonBuilder.registerTypeAdapter(XapiActor.class, new XapiActorJson()); gsonBuilder.registerTypeAdapter(XapiAgent.class, new XapiAgentJson()); gsonBuilder.registerTypeAdapter(XapiGroup.class, new XapiGroupJson()); gsonBuilder.registerTypeAdapter(XapiInverseFunctionalIdentifier.class, new XapiInverseFuncIdJson()); gsonBuilder.registerTypeAdapter(XapiAccount.class, new XapiAccountJson()); gsonBuilder.registerTypeAdapter(XapiVerb.class, new XapiVerbJson()); gsonBuilder.registerTypeAdapter(XapiObject.class, new XapiObjectJson()); gsonBuilder.registerTypeAdapter(XapiStatementRef.class, new XapiStatementRefJson()); gsonBuilder.registerTypeAdapter(XapiSubStatement.class, new XapiSubStatementJson()); gsonBuilder.registerTypeAdapter(XapiActivity.class, new XapiActivityJson()); gsonBuilder.registerTypeAdapter(XapiActivityDefinition.class, new XapiActivityDefinitionJson()); gsonBuilder.registerTypeAdapter(XapiLanguageMap.class, new XapiLanguageMapJson()); gsonBuilder.registerTypeAdapter(XapiResult.class, new XapiResultJson()); gsonBuilder.registerTypeAdapter(XapiScore.class, new XapiScoreJson()); gsonBuilder.registerTypeAdapter(XapiContextActivities.class, new XapiContextActivitiesJson()); gsonBuilder.registerTypeAdapter(XapiContext.class, new XapiContextJson()); gsonBuilder.registerTypeAdapter(XapiInteraction.class, new XapiInteractionJson()); gsonBuilder.registerTypeAdapter(XapiInteractionComponent.class, new XapiInteractionComponentJson()); gsonBuilder.registerTypeAdapter(XapiCredentials.class, new XapiCredentialsJson()); gsonBuilder.registerTypeAdapter(XapiStatementBatch.class, new XapiStatementBatchJson()); gsonBuilder.registerTypeAdapter(XapiPerson.class, new XapiPersonJson()); gsonBuilder.registerTypeAdapter(XapiStatementResult.class, new XapiStatementResultJson()); gsonBuilder.registerTypeAdapter(XapiExtension.class, new XapiExtensionsJson()); gsonBuilder.registerTypeAdapter(XapiCredentialsList.class, new XapiCredentialsListJson()); final Gson gson = gsonBuilder.create(); return gson; }
From source file:com.cleanappsample.di.RootModule.java
License:Apache License
@Provides Gson provideGson() {//from www .j a v a2 s.co m GsonBuilder builder = new GsonBuilder(); builder.registerTypeAdapterFactory(new AutoValueAdapterFactory()); builder.serializeNulls(); return builder.create(); }
From source file:com.cloud.agent.api.NetworkIngressRulesCmd.java
License:Open Source License
public String toJson() { GsonBuilder gBuilder = new GsonBuilder(); Gson json = gBuilder.create(); return json.toJson(this); }
From source file:com.cloud.agent.api.NetworkIngressRulesCmd.java
License:Open Source License
public static NetworkIngressRulesCmd fromJson(String jsonString) { GsonBuilder gBuilder = new GsonBuilder(); Gson json = gBuilder.create(); return json.fromJson(jsonString, NetworkIngressRulesCmd.class); }
From source file:com.cloud.agent.api.SecurityIngressRulesCmd.java
License:Open Source License
public static SecurityIngressRulesCmd fromJson(String jsonString) { GsonBuilder gBuilder = new GsonBuilder(); Gson json = gBuilder.create(); return json.fromJson(jsonString, SecurityIngressRulesCmd.class); }
From source file:com.cloud.consoleproxy.ConsoleProxyManagerImpl.java
License:Apache License
private boolean hasPreviousSession(ConsoleProxyVO proxy, VMInstanceVO vm) { ConsoleProxyStatus status = null;/*from www . jav a 2 s.co m*/ try { GsonBuilder gb = new GsonBuilder(); gb.setVersion(1.3); Gson gson = gb.create(); byte[] details = proxy.getSessionDetails(); status = gson.fromJson(details != null ? new String(details, Charset.forName("US-ASCII")) : null, ConsoleProxyStatus.class); } catch (Throwable e) { s_logger.warn("Unable to parse proxy session details : " + proxy.getSessionDetails()); } if (status != null && status.getConnections() != null) { ConsoleProxyConnectionInfo[] connections = status.getConnections(); for (int i = 0; i < connections.length; i++) { long taggedVmId = 0; if (connections[i].tag != null) { try { taggedVmId = Long.parseLong(connections[i].tag); } catch (NumberFormatException e) { s_logger.warn("Unable to parse console proxy connection info passed through tag: " + connections[i].tag, e); } } if (taggedVmId == vm.getId()) { return true; } } // // even if we are not in the list, it may because we haven't // received load-update yet // wait until session time // if (DateUtil.currentGMTTime().getTime() - vm.getProxyAssignTime().getTime() < _proxySessionTimeoutValue) { return true; } return false; } else { s_logger.error("No proxy load info on an overloaded proxy ?"); return false; } }
From source file:com.cloud.consoleproxy.ConsoleProxyManagerImpl.java
License:Apache License
public void onLoadAnswer(ConsoleProxyLoadAnswer answer) { if (answer.getDetails() == null) { return;/*from www . ja v a 2 s .co m*/ } ConsoleProxyStatus status = null; try { GsonBuilder gb = new GsonBuilder(); gb.setVersion(1.3); Gson gson = gb.create(); status = gson.fromJson(answer.getDetails(), ConsoleProxyStatus.class); } catch (Throwable e) { s_logger.warn("Unable to parse load info from proxy, proxy vm id : " + answer.getProxyVmId() + ", info : " + answer.getDetails()); } if (status != null) { int count = 0; if (status.getConnections() != null) { count = status.getConnections().length; } byte[] details = null; if (answer.getDetails() != null) { details = answer.getDetails().getBytes(Charset.forName("US-ASCII")); } _consoleProxyDao.update(answer.getProxyVmId(), count, DateUtil.currentGMTTime(), details); } else { if (s_logger.isTraceEnabled()) { s_logger.trace("Unable to get console proxy load info, id : " + answer.getProxyVmId()); } _consoleProxyDao.update(answer.getProxyVmId(), 0, DateUtil.currentGMTTime(), null); // TODO : something is wrong with the VM, restart it? } }