List of usage examples for com.google.gson.internal.bind DateTypeAdapter DateTypeAdapter
public DateTypeAdapter()
From source file:click.kobaken.rxirohaandroid.di.IrohaModule.java
License:Open Source License
private Gson createGson() { return new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES) .registerTypeAdapter(Date.class, new DateTypeAdapter()).create(); }
From source file:cn.teamlab.wg.framework.struts2.json.JsonSerializerBuilder.java
License:Apache License
public static GsonBuilder builder() { return new GsonBuilder() // .disableHtmlEscaping().registerTypeAdapter(Double.class, new JsonSerializer<Double>() { @Override//from w w w . j a va 2s .c o m public JsonElement serialize(Double src, Type typeOfSrc, JsonSerializationContext context) { if (src == src.longValue()) return new JsonPrimitive(src.longValue()); return new JsonPrimitive(src); } }).registerTypeAdapter(Date.class, new DateTypeAdapter()) .registerTypeAdapter(DateTime.class, new JsonSerializer<DateTime>() { @Override public JsonElement serialize(DateTime arg0, Type arg1, JsonSerializationContext arg2) { return new JsonPrimitive(arg0.toString(DateFormatter.SDF_YMDHMS6)); } }); }
From source file:com.ahmadrosid.lib.baseapp.core.BasePresenter.java
License:Apache License
public BasePresenter(T mvpView) { this.mvpView = mvpView; gson = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES) .setPrettyPrinting().registerTypeAdapter(Date.class, new DateTypeAdapter()).create(); }
From source file:com.android.example.leanback.fastlane.LeanbackBrowseFragment.java
License:Open Source License
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); Gson gson = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES) .registerTypeAdapter(Date.class, new DateTypeAdapter()).create(); RestAdapter restAdapter = new RestAdapter.Builder().setEndpoint("https://hub.gdgx.io/api/v1/") .setConverter(new GsonConverter(gson)).build(); HubApiService hubApiService = restAdapter.create(HubApiService.class); hubApiService.getAllGdes(this); }
From source file:com.caihan.scframe.utils.json.gson.GsonConvertUtils.java
License:Apache License
public static String formatJson(String json) { try {/*from w w w .ja v a 2 s. co m*/ JsonParser jp = new JsonParser(); JsonElement je = jp.parse(json); return new GsonBuilder().setPrettyPrinting() .setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES) .registerTypeAdapter(Date.class, new DateTypeAdapter()).create().toJson(je); } catch (Exception e) { return json; } }
From source file:com.caihan.scframe.utils.json.gson.GsonConvertUtils.java
License:Apache License
public static String formatJson(Object src) { try {/*from w ww . j a v a 2 s . c o m*/ JsonParser jp = new JsonParser(); JsonElement je = jp.parse(toJson(src)); return new GsonBuilder().setPrettyPrinting() .setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES) .registerTypeAdapter(Date.class, new DateTypeAdapter()).create().toJson(je); } catch (Exception e) { return e.getMessage(); } }
From source file:com.jlubecki.soundcloud.webapi.android.SoundCloudAPI.java
License:Open Source License
/** * Creates a {@link SoundCloudService}. Serializes with JSON. * * @param clientId Client ID provided by SoundCloud. *//*from w w w .j a v a 2s .co m*/ public SoundCloudAPI(String clientId) { this.clientId = clientId; Gson gson = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES) .registerTypeAdapter(Date.class, new DateTypeAdapter()).create(); OkHttpClient client = new OkHttpClient.Builder().addInterceptor(new SoundCloudInterceptor()).build(); Retrofit adapter = new Retrofit.Builder().client(client).baseUrl(SOUNDCLOUD_API_ENDPOINT) .addConverterFactory(GsonConverterFactory.create(gson)).build(); service = adapter.create(SoundCloudService.class); }
From source file:com.readystatesoftware.chuck.internal.support.JsonConvertor.java
License:Apache License
public static Gson getInstance() { if (gson == null) { gson = new GsonBuilder().setPrettyPrinting() .setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES) .registerTypeAdapter(Date.class, new DateTypeAdapter()).create(); }//from ww w . ja va 2 s. c om return gson; }
From source file:com.shipdream.lib.android.mvc.controller.RetrofitServiceFactory.java
License:Apache License
public RetrofitServiceFactory(String endpoint, Client client) { this.endpoint = endpoint; this.client = client; if (this.endpoint != null) { gson = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.IDENTITY) .registerTypeAdapter(Date.class, new DateTypeAdapter()).create(); jsonConverter = new FlexibleConverter(gson, "UTF-8", onSuccessListeners); recreateRestAdapter();//from ww w. j a va 2 s .com } }
From source file:com.sociablue.nanodegree_p1.managers.NetworkManager.java
License:Apache License
public NetworkManager() { Gson gson = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES) .registerTypeAdapter(Date.class, new DateTypeAdapter()).create(); RestAdapter restAdapter = new RestAdapter.Builder().setEndpoint(MdbConstants.BASE_URL) .setConverter(new GsonConverter(gson)).build(); MdbService = restAdapter.create(MDB.class); }