List of usage examples for com.google.gson FieldNamingPolicy LOWER_CASE_WITH_UNDERSCORES
FieldNamingPolicy LOWER_CASE_WITH_UNDERSCORES
To view the source code for com.google.gson FieldNamingPolicy LOWER_CASE_WITH_UNDERSCORES.
Click Source Link
From source file:org.gdg.frisbee.android.api.GroupDirectory.java
License:Apache License
public ApiRequest getDirectory(Response.Listener<Directory> successListener, Response.ErrorListener errorListener) { GsonRequest<Void, Directory> dirReq = new GsonRequest<>(Request.Method.GET, DIRECTORY_URL, Directory.class, successListener, errorListener, GsonRequest.getGson(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)); return new ApiRequest(dirReq); }
From source file:org.gdg.frisbee.android.api.GroupDirectory.java
License:Apache License
public ApiRequest getPulse(Response.Listener<Pulse> successListener, Response.ErrorListener errorListener) { GsonRequest<Void, Pulse> pulseReq = new GsonRequest<>(Request.Method.GET, PULSE_URL, Pulse.class, successListener, errorListener, GsonRequest.getGson(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)); return new ApiRequest(pulseReq); }
From source file:org.gdg.frisbee.android.api.GroupDirectory.java
License:Apache License
public ApiRequest getCountryPulse(String country, Response.Listener<Pulse> successListener, Response.ErrorListener errorListener) { GsonRequest<Void, Pulse> pulseReq = null; try {//from www .ja v a 2 s.co m Timber.d(String.format(COUNTRY_PULSE_URL, URLEncoder.encode(country, "utf-8"))); pulseReq = new GsonRequest<>(Request.Method.GET, String.format(COUNTRY_PULSE_URL, country.replaceAll(" ", "%20")), Pulse.class, successListener, errorListener, GsonRequest.getGson(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)); } catch (UnsupportedEncodingException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } return new ApiRequest(pulseReq); }
From source file:org.gdg.frisbee.android.fragment.ContributorsFragment.java
License:Apache License
private void fetchGitHubContributors() { GitHub gitHubClient = new RestAdapter.Builder().setEndpoint("https://api.github.com") .setConverter(new GsonConverter(Utils.getGson(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES))) .build().create(GitHub.class); gitHubClient.getContributors(Const.GITHUB_ORGA, Const.GITHUB_REPO, new Callback<ContributorList>() { @Override/*from w w w . ja v a 2 s. c o m*/ public void success(final ContributorList contributors, retrofit.client.Response response) { App.getInstance().getModelCache().putAsync(Const.CACHE_KEY_FRISBEE_CONTRIBUTORS, contributors, DateTime.now().plusDays(1), new ModelCache.CachePutListener() { @Override public void onPutIntoCache() { mAdapter.addAll(contributors); } }); } @Override public void failure(RetrofitError error) { } }); }
From source file:org.hyperic.hq.plugin.rabbitmq.core.HypericRabbitAdmin.java
License:Open Source License
private <T extends Object> T get(String api, Class<T> classOfT) throws PluginException { T res = null;//from ww w .ja v a2 s . c o m try { HttpGet get = new HttpGet(targetHost.toURI() + api); HttpResponse response = client.execute(get, localcontext); int r = response.getStatusLine().getStatusCode(); // response must be read in order to "close" the connection. // https://jira.hyperic.com/browse/HHQ-5063#comment-154101 String responseBody = readInputString(response.getEntity().getContent()); if (logger.isDebugEnabled()) { logger.debug("[" + api + "] -(" + r + ")-> " + responseBody); } if (r != 200) { throw new PluginException("[" + api + "] http error code: '" + r + "'"); } GsonBuilder gsb = new GsonBuilder(); gsb.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES); gsb.registerTypeAdapter(Integer.class, new IntegerDeserializer()); gsb.registerTypeAdapter(int.class, new IntegerDeserializer()); gsb.registerTypeAdapter(Date.class, new DateTimeDeserializer()); gsb.registerTypeAdapter(MessageStats.class, new MessageStatsDeserializer()); Gson gson = gsb.create(); res = gson.fromJson(responseBody, classOfT); if (logger.isDebugEnabled()) { if (res.getClass().isArray()) { logger.debug("[" + api + "] -(" + r + ")*> " + Arrays.asList((Object[]) res)); } else { logger.debug("[" + api + "] -(" + r + ")-> " + res); } } } catch (IOException ex) { logger.debug(ex.getMessage(), ex); throw new PluginException(ex.getMessage(), ex); } return res; }
From source file:org.indonesiax.mobile.discussion.DiscussionAPI.java
License:Open Source License
@Inject public DiscussionAPI(Context context, Config config, OkHttpClient client) { this.context = context; this.config = config; Gson gson = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES) .setDateFormat(DateUtil.ISO_8601_DATE_TIME_FORMAT).create(); RestAdapter restAdapter = new RestAdapter.Builder().setClient(new OkClient(client)) .setEndpoint(config.getApiHostURL()).setConverter(new GsonConverter(gson)) .setErrorHandler(new RetroHttpExceptionHandler()).setLogLevel(RestAdapter.LogLevel.FULL).build(); discussionService = restAdapter.create(DiscussionService.class); }
From source file:org.jclouds.openstack.poppy.v1.config.PoppyHttpApiModule.java
License:Apache License
@Override protected void configure() { bind(new TypeLiteral<Supplier<URI>>() { }).annotatedWith(CDN.class).to(new TypeLiteral<Supplier<URI>>() { });/*from w w w .java 2s . c o m*/ bind(FieldNamingPolicy.class).toInstance(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES); bind(DateAdapter.class).to(Iso8601DateAdapter.class); super.configure(); }
From source file:org.kairosdb.core.http.rest.json.QueryParser.java
License:Apache License
@Inject public QueryParser(AggregatorFactory aggregatorFactory, GroupByFactory groupByFactory, QueryPluginFactory pluginFactory) { m_aggregatorFactory = aggregatorFactory; m_groupByFactory = groupByFactory;// w ww. ja v a 2s .c om m_pluginFactory = pluginFactory; m_descriptorMap = new HashMap<Class, Map<String, PropertyDescriptor>>(); GsonBuilder builder = new GsonBuilder(); builder.registerTypeAdapterFactory(new LowercaseEnumTypeAdapterFactory()); builder.registerTypeAdapter(TimeUnit.class, new TimeUnitDeserializer()); builder.registerTypeAdapter(DateTimeZone.class, new DateTimeZoneDeserializer()); builder.registerTypeAdapter(Metric.class, new MetricDeserializer()); builder.registerTypeAdapter(SetMultimap.class, new SetMultimapDeserializer()); builder.registerTypeAdapter(RelativeTime.class, new RelativeTimeSerializer()); builder.registerTypeAdapter(SetMultimap.class, new SetMultimapSerializer()); builder.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES); m_gson = builder.create(); }
From source file:org.kontalk.xmppserver.registration.jmp.JmpVerifyClient.java
License:Open Source License
private Retrofit buildRetrofit() { Gson gson = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).create(); return new Retrofit.Builder().baseUrl(baseUrl).addConverterFactory(GsonConverterFactory.create(gson)) .build();//from ww w . j a va 2 s. c om }
From source file:org.lastaflute.core.json.engine.GsonJsonEngine.java
License:Apache License
protected FieldNamingPolicy deriveFieldNamingPolicy(JsonFieldNaming naming) { final FieldNamingPolicy policy; if (naming == JsonFieldNaming.IDENTITY) { policy = FieldNamingPolicy.IDENTITY; } else if (naming == JsonFieldNaming.CAMEL_TO_LOWER_SNAKE) { policy = FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES; } else {// w w w .jav a 2s . c o m throw new IllegalStateException("Unknown field naming: " + naming); } return policy; }