Example usage for com.google.gson GsonBuilder setDateFormat

List of usage examples for com.google.gson GsonBuilder setDateFormat

Introduction

In this page you can find the example usage for com.google.gson GsonBuilder setDateFormat.

Prototype

public GsonBuilder setDateFormat(int style) 

Source Link

Document

Configures Gson to to serialize Date objects according to the style value provided.

Usage

From source file:com.sire.web.UserManager.java

public UserManager() {
    vVendedorFacadeREST = new VVendedorFacadeREST();
    GsonBuilder builder = new GsonBuilder();
    gson = builder.setDateFormat("yyyy-MM-dd'T'HH:mm:ss").create();
    gnrEmpresa = new GnrEmpresa();
}

From source file:com.springer.api.services.impl.BaseSpringerQuery.java

License:Apache License

/**
 * Gets the gson builder.//from w  w  w. jav a  2  s .c  o  m
 * 
 * @return the gson builder
 */
protected GsonBuilder getGsonBuilder() {
    GsonBuilder builder = new GsonBuilder();
    builder.setDateFormat(ApplicationConstants.DATE_FORMAT);
    //      builder.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES);
    //      builder.registerTypeAdapter(Issue.State.class, new JsonDeserializer<Issue.State>() {
    //         @Override
    //         public Issue.State deserialize(JsonElement arg0, Type arg1,
    //               JsonDeserializationContext arg2) throws JsonParseException {
    //            return Issue.State.fromValue(arg0.getAsString());
    //         }
    //      });
    return builder;
}

From source file:com.synckware.flyhttp.library.utils.ConverterJSONToArray.java

License:Apache License

public ArrayList<T> toArrayList(String jsonString, Class<T> clazz) {
    GsonBuilder builder = new GsonBuilder();
    builder.setDateFormat("dd/MM/yy HH:mm:ss");
    Gson gson = builder.create();//from w  w w  . java2 s.co  m
    ListParameterizedType type = new ListParameterizedType(clazz);
    ArrayList list = (ArrayList) gson.fromJson(jsonString, type);
    return list;
}

From source file:com.unovo.frame.utils.gson.GsonHelper.java

License:Open Source License

private static Gson createGson() {
    GsonBuilder gsonBuilder = new GsonBuilder();
    //gsonBuilder.setExclusionStrategies(new SpecificClassExclusionStrategy(null, Model.class));
    gsonBuilder.setDateFormat("yyyy-MM-dd HH:mm:ss");

    JsonDeserializer deserializer = new IntegerJsonDeserializer();
    gsonBuilder.registerTypeAdapter(int.class, deserializer);
    gsonBuilder.registerTypeAdapter(Integer.class, deserializer);

    deserializer = new FloatJsonDeserializer();
    gsonBuilder.registerTypeAdapter(float.class, deserializer);
    gsonBuilder.registerTypeAdapter(Float.class, deserializer);

    deserializer = new DoubleJsonDeserializer();
    gsonBuilder.registerTypeAdapter(double.class, deserializer);
    gsonBuilder.registerTypeAdapter(Double.class, deserializer);

    deserializer = new StringJsonDeserializer();
    gsonBuilder.registerTypeAdapter(String.class, deserializer);

    deserializer = new ListJsonDeserializer();
    gsonBuilder.registerTypeAdapter(List.class, deserializer);

    return gsonBuilder.create();
}

From source file:com.ushahidi.android.data.api.BaseApiTestCase.java

License:Open Source License

@Before
public void setUp() throws IOException {
    GsonBuilder builder = new GsonBuilder();
    builder.setDateFormat("yyyy-MM-dd'T'HH:mm:ssX");
    builder.registerTypeAdapter(Date.class, new DateDeserializer());
    mGson = builder.create();/*from ww w.  j a va  2s .  co m*/
}

From source file:com.ushahidi.android.data.api.PlatformService.java

License:Open Source License

private void initializeGson() {
    GsonBuilder builder = new GsonBuilder();
    builder.setDateFormat("yyyy-MM-dd'T'HH:mm:ss");
    builder.registerTypeAdapter(Date.class, new DateDeserializer());
    builder.registerTypeAdapter(PostValueEntity.class, new ValueDeserializer());
    Gson gson = builder.create();//from   w ww. j a v  a 2  s  .co m
    mGsonConverter = new GsonConverter(gson);
}

From source file:com.ushahidi.android.data.BaseTestCase.java

License:Open Source License

@Before
public void setUp() throws Exception {
    GsonBuilder builder = new GsonBuilder();
    builder.setDateFormat("yyyy-MM-dd'T'HH:mm:ssX");
    builder.registerTypeAdapter(Date.class, new DateDeserializer());
    builder.registerTypeAdapter(PostValueEntity.class, new ValueDeserializer());
    mGson = builder.create();/*from w ww  .  j a v  a2  s .c  o m*/

}

From source file:com.ushahidi.android.util.ApiServiceUtil.java

License:Open Source License

public <T> T createService(Class<T> serviceClass, String baseUrl, final String accessToken) {

    Preconditions.checkNotNull(serviceClass);

    ApiHeader header = new ApiHeader(accessToken);
    Endpoint endpoint = Endpoints.newFixedEndpoint(baseUrl);
    GsonBuilder builder = new GsonBuilder();
    builder.setDateFormat("yyyy-MM-dd'T'HH:mm:ss");
    builder.registerTypeAdapter(Date.class, new DateDeserializer());
    builder.registerTypeAdapter(PostValueEntity.class, new ValueDeserializer());
    Gson gson = builder.create();//from  w  ww.j  a  v  a  2 s.  com
    RestAdapter restAdapter = new RestAdapter.Builder().setConverter(new GsonConverter(gson)).setClient(mClient)
            .setEndpoint(endpoint).setLogLevel(RestAdapter.LogLevel.FULL)
            .setErrorHandler(mUnauthorizedAccessErrorHandler).setRequestInterceptor(header).build();

    return restAdapter.create(serviceClass);
}

From source file:com.ushahidi.platform.mobile.app.data.api.PlatformService.java

License:Open Source License

private void initializeGson() {
    GsonBuilder builder = new GsonBuilder();
    builder.setDateFormat("yyyy-MM-dd'T'HH:mm:ss");
    builder.registerTypeAdapter(Date.class, new DateDeserializer());
    builder.registerTypeAdapter(PostValueEntity.class, new PostValueDeserializer());
    builder.registerTypeAdapter(AllowedPrivilegesEntity.class, new AllowedPrivilegesDeserializer());
    builder.registerTypeAdapter(PostCompletedStagesEntity.class, new PostCompletedStagesDeserializer());
    builder.registerTypeAdapter(PostPublishedToEntity.class, new PostPublishToDeserializer());
    Gson gson = builder.create();/* w  ww. j a  va  2 s. c  o  m*/
    mGsonConverter = new GsonConverter(gson);
}

From source file:com.webservice.MovieService.java

public String toJSONString(Object object) {
    GsonBuilder gsonBuilder = new GsonBuilder();
    gsonBuilder.setDateFormat("yyy-MM-dd'T'HH:mm:ss.SSS'Z'"); // UTC
    Gson gson = gsonBuilder.create();//  w  ww.j a v a 2 s. co m
    return gson.toJson(object);
}