Example usage for com.google.gson JsonPrimitive JsonPrimitive

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

Introduction

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

Prototype

public JsonPrimitive(Character c) 

Source Link

Document

Create a primitive containing a character.

Usage

From source file:com.aaasec.sigserv.cscommon.json.DateTypeAdapter.java

License:EUPL

public JsonElement serialize(Date src, Type typeOfSrc, JsonSerializationContext context) {
    String dateFormatAsString = format.format(src);
    return new JsonPrimitive(dateFormatAsString);
}

From source file:com.actimem.blog.gson.customtypes.CompanyIdAdapter.java

License:Apache License

@Override
public JsonElement serialize(CompanyId src, Type typeOfSrc, JsonSerializationContext context) {
    return new JsonPrimitive(src.getId());
}

From source file:com.actimem.blog.gson.customtypes.DateTimeAdapter.java

License:Apache License

@Override
public JsonElement serialize(DateTime src, Type typeOfSrc, JsonSerializationContext context) {
    return new JsonPrimitive(src.toString());
}

From source file:com.actionml.DateTimeAdapter.java

License:Apache License

public JsonElement serialize(DateTime src, Type type, JsonSerializationContext context) {
    return new JsonPrimitive(src.toString());
}

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

License:Apache License

@Inject
public NewSignalEntityJsonMapper() {
    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 www  .j ava2  s.  c  o m*/

}

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

License:Apache License

@Inject
public SignalEntityJsonMapper() {
    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  w w . j a v a2  s  .c o  m*/

}

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();/*from w ww .ja v  a 2  s. c  om*/

}

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();/*from w ww. j  a v  a 2 s. 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 w w .  ja  v a2 s.  com
}

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 . ja v a  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;
}