Example usage for com.google.gson GsonBuilder GsonBuilder

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

Introduction

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

Prototype

public GsonBuilder() 

Source Link

Document

Creates a GsonBuilder instance that can be used to build Gson with various configuration settings.

Usage

From source file:com.adnanbal.fxdedektifi.forex.data.entity.mapper.Signal_UserEntityJsonMapper.java

License:Apache License

@Inject
public Signal_UserEntityJsonMapper() {
    this.gson = new GsonBuilder()
            .registerTypeAdapter(Date.class,
                    (JsonDeserializer<Date>) (jsonElement, type,
                            context) -> new Date(jsonElement.getAsJsonPrimitive().getAsLong()))
            .registerTypeAdapter(Date.class,
                    (JsonSerializer<Date>) (date, type,
                            jsonSerializationContext) -> new JsonPrimitive(date.getTime()))

            .create();//w ww.  j  ava  2  s . c  o m

}

From source file:com.adnanbal.fxdedektifi.forex.data.entity.mapper.SubscriptionEntityJsonMapper.java

License:Apache License

@Inject
public SubscriptionEntityJsonMapper() {
    this.gson = new GsonBuilder()
            .registerTypeAdapter(Date.class,
                    (JsonDeserializer<Date>) (jsonElement, type,
                            context) -> new Date(jsonElement.getAsJsonPrimitive().getAsLong()))
            .registerTypeAdapter(Date.class,
                    (JsonSerializer<Date>) (date, type,
                            jsonSerializationContext) -> new JsonPrimitive(date.getTime()))

            .create();//  w ww .  j  a v a2s  .c om

}

From source file:com.adnanbal.fxdedektifi.forex.data.entity.mapper.UserLoginDetailsEntityJsonMapper.java

License:Apache License

@Inject
public UserLoginDetailsEntityJsonMapper() {
    this.gson = new GsonBuilder()
            .registerTypeAdapter(Date.class,
                    (JsonDeserializer<Date>) (jsonElement, type, context) -> new Date(
                            jsonElement.getAsJsonPrimitive().getAsLong()))
            .registerTypeAdapter(Date.class, (JsonSerializer<Date>) (date, type,
                    jsonSerializationContext) -> new JsonPrimitive(date.getTime()))
            .create();//from   w  ww.  j av  a 2s .  c  o  m
}

From source file:com.adnanbal.fxdedektifi.forex.data.net.ApiConnection.java

License:Apache License

/**
 * Do a request to an api synchronously.
 * It should not be executed in the main thread of the application.
 *
 * @return A string response/*from   w  w w.  j  a  va  2  s.c  o  m*/
 */
@Nullable
String request_postSyncCall(PositionEntity positionEntity) {
    final MediaType JSON = MediaType.parse("application/json; charset=utf-8");

    Gson gson = new GsonBuilder()
            .registerTypeAdapter(Date.class,
                    (JsonDeserializer<Date>) (jsonElement, type,
                            context) -> new Date(jsonElement.getAsJsonPrimitive().getAsLong()))
            .registerTypeAdapter(Date.class,
                    (JsonSerializer<Date>) (date, type,
                            jsonSerializationContext) -> new JsonPrimitive(date.getTime()))

            .create();
    String jsonInString = gson.toJson(positionEntity);

    RequestBody body = RequestBody.create(JSON, jsonInString);

    postRequestToApi(body);
    i++;
    return response;
}

From source file:com.adnanbal.fxdedektifi.forex.data.net.ApiConnection.java

License:Apache License

/**
 * Do a request to an api synchronously.
 * It should not be executed in the main thread of the application.
 *
 * @return A string response// ww  w  . j  a v a  2s.c o  m
 */
@Nullable
String request_postSyncCall(NewPositionEntity newPositionEntity) {
    final MediaType JSON = MediaType.parse("application/json; charset=utf-8");

    Gson gson = new GsonBuilder()
            .registerTypeAdapter(Date.class,
                    (JsonDeserializer<Date>) (jsonElement, type,
                            context) -> new Date(jsonElement.getAsJsonPrimitive().getAsLong()))
            .registerTypeAdapter(Date.class,
                    (JsonSerializer<Date>) (date, type,
                            jsonSerializationContext) -> new JsonPrimitive(date.getTime()))

            .create();
    String jsonInString = gson.toJson(newPositionEntity);

    RequestBody body = RequestBody.create(JSON, jsonInString);

    postRequestToApi(body);
    i++;
    return response;
}

From source file:com.adnanbal.fxdedektifi.forex.data.net.ApiConnection.java

License:Apache License

@Nullable
String request_postNewSignalSyncCall(NewPositionEntity newPositionEntity) {
    final MediaType JSON = MediaType.parse("application/json; charset=utf-8");

    Gson gson = new GsonBuilder()
            .registerTypeAdapter(Date.class,
                    (JsonDeserializer<Date>) (jsonElement, type,
                            context) -> new Date(jsonElement.getAsJsonPrimitive().getAsLong()))
            .registerTypeAdapter(Date.class,
                    (JsonSerializer<Date>) (date, type,
                            jsonSerializationContext) -> new JsonPrimitive(date.getTime()))

            .create();/*from w ww  . j a  v a2 s.c om*/
    String jsonInString = gson.toJson(newPositionEntity);

    RequestBody body = RequestBody.create(JSON, jsonInString);

    postRequestToApiNewSignal(body);
    i++;
    return response;
}

From source file:com.adnanbal.fxdedektifi.forex.data.net.ApiConnection.java

License:Apache License

/**
 * Do a request to an api synchronously.
 * It should not be executed in the main thread of the application.
 *
 * @return A string response//w  ww  .j a va 2s .co m
 */
@Nullable
String request_postUserLoginDetailEntitySyncCall(UserLoginDetailsEntity userLoginDetailsEntity) {
    final MediaType JSON = MediaType.parse("application/json; charset=utf-8");

    Gson gson = new GsonBuilder()
            .registerTypeAdapter(Date.class,
                    (JsonDeserializer<Date>) (jsonElement, type,
                            context) -> new Date(jsonElement.getAsJsonPrimitive().getAsLong()))
            .registerTypeAdapter(Date.class,
                    (JsonSerializer<Date>) (date, type,
                            jsonSerializationContext) -> new JsonPrimitive(date.getTime()))

            .create();
    String jsonInString = gson.toJson(userLoginDetailsEntity);

    RequestBody body = RequestBody.create(JSON, jsonInString);

    postRequestToApi(body);
    i++;
    return response;
}

From source file:com.adnanbal.fxdedektifi.forex.data.net.ApiConnection.java

License:Apache License

@Nullable
String request_putSyncCall(PositionEntity positionEntity) {
    final MediaType JSON = MediaType.parse("application/json; charset=utf-8");

    Gson gson = new GsonBuilder()
            .registerTypeAdapter(Date.class,
                    (JsonDeserializer<Date>) (jsonElement, type,
                            context) -> new Date(jsonElement.getAsJsonPrimitive().getAsLong()))
            .registerTypeAdapter(Date.class,
                    (JsonSerializer<Date>) (date, type,
                            jsonSerializationContext) -> new JsonPrimitive(date.getTime()))

            .create();/*from   w  w w  .  j ava 2  s.c o  m*/
    String jsonInString = gson.toJson(positionEntity);

    RequestBody body = RequestBody.create(JSON, jsonInString);

    postRequestToApi(body);
    i++;
    return response;
}

From source file:com.adnanbal.fxdedektifi.forex.data.net.ApiConnection.java

License:Apache License

@Nullable
String request_putNewSignalSyncCall(NewPositionEntity newPositionEntity) {
    final MediaType JSON = MediaType.parse("application/json; charset=utf-8");

    Gson gson = new GsonBuilder()
            .registerTypeAdapter(Date.class,
                    (JsonDeserializer<Date>) (jsonElement, type,
                            context) -> new Date(jsonElement.getAsJsonPrimitive().getAsLong()))
            .registerTypeAdapter(Date.class,
                    (JsonSerializer<Date>) (date, type,
                            jsonSerializationContext) -> new JsonPrimitive(date.getTime()))

            .create();//from  www  .  j a  v  a2s  .  co  m
    String jsonInString = gson.toJson(newPositionEntity);

    RequestBody body = RequestBody.create(JSON, jsonInString);

    putRequestToApi(body);
    i++;
    return response;
}

From source file:com.adnanbal.fxdedektifi.forex.data.net.ApiConnection.java

License:Apache License

@Nullable
String request_patchSyncCall(Map<String, Boolean> userSignalMap) {
    final MediaType JSON = MediaType.parse("application/json; charset=utf-8");

    Gson gson = new GsonBuilder()
            .registerTypeAdapter(Date.class,
                    (JsonDeserializer<Date>) (jsonElement, type,
                            context) -> new Date(jsonElement.getAsJsonPrimitive().getAsLong()))
            .registerTypeAdapter(Date.class,
                    (JsonSerializer<Date>) (date, type,
                            jsonSerializationContext) -> new JsonPrimitive(date.getTime()))

            .create();//from www.j ava2 s  . c o m
    String jsonInString = gson.toJson(userSignalMap);

    RequestBody body = RequestBody.create(JSON, jsonInString);

    patchRequestToApi(body);
    i++;
    return response;
}