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.fatboyindustrial.gsonjavatime.LocalTimeConverter.java

License:Open Source License

/**
 * Gson invokes this call-back method during serialization when it encounters a field of the specified type.
 * <p>//  www .  j a v a  2s  .  c  om
 *
 * In the implementation of this call-back method, you should consider invoking
 * {@link JsonSerializationContext#serialize(Object, Type)} method to create JsonElements for any non-trivial field of the
 * {@code src} object. However, you should never invoke it on the {@code src} object itself since that will cause an
 * infinite loop (Gson will call your call-back method again).
 *
 * @param src the object that needs to be converted to Json.
 * @param typeOfSrc the actual type (fully genericized version) of the source object.
 * @return a JsonElement corresponding to the specified object.
 */
@Override
public JsonElement serialize(LocalTime src, Type typeOfSrc, JsonSerializationContext context) {
    return new JsonPrimitive(getFormatter().format(src));
}

From source file:com.fatboyindustrial.gsonjavatime.OffsetDateTimeConverter.java

License:Open Source License

/**
 * Gson invokes this call-back method during serialization when it encounters a field of the specified type.
 * <p>//from   ww  w.j  a va2s  . c om
 *
 * In the implementation of this call-back method, you should consider invoking
 * {@link JsonSerializationContext#serialize(Object, Type)} method to create JsonElements for any non-trivial field of the
 * {@code src} object. However, you should never invoke it on the {@code src} object itself since that will cause an
 * infinite loop (Gson will call your call-back method again).
 *
 * @param src the object that needs to be converted to Json.
 * @param typeOfSrc the actual type (fully genericized version) of the source object.
 * @return a JsonElement corresponding to the specified object.
 */
@Override
public JsonElement serialize(OffsetDateTime src, Type typeOfSrc, JsonSerializationContext context) {
    return new JsonPrimitive(getFormatter().format(src));
}

From source file:com.fatboyindustrial.gsonjavatime.OffsetTimeConverter.java

License:Open Source License

/**
 * Gson invokes this call-back method during serialization when it encounters a field of the specified type.
 * <p>// w ww.  ja  v a2s  .  c o  m
 *
 * In the implementation of this call-back method, you should consider invoking
 * {@link JsonSerializationContext#serialize(Object, Type)} method to create JsonElements for any non-trivial field of the
 * {@code src} object. However, you should never invoke it on the {@code src} object itself since that will cause an
 * infinite loop (Gson will call your call-back method again).
 *
 * @param src the object that needs to be converted to Json.
 * @param typeOfSrc the actual type (fully genericized version) of the source object.
 * @return a JsonElement corresponding to the specified object.
 */
@Override
public JsonElement serialize(OffsetTime src, Type typeOfSrc, JsonSerializationContext context) {
    return new JsonPrimitive(getFormatter().format(src));
}

From source file:com.fatboyindustrial.gsonjavatime.ZonedDateTimeConverter.java

License:Open Source License

/**
 * Gson invokes this call-back method during serialization when it encounters a field of the specified type.
 * <p>/*w w  w  .  j  ava2 s  .co m*/
 *
 * In the implementation of this call-back method, you should consider invoking
 * {@link JsonSerializationContext#serialize(Object, Type)} method to create JsonElements for any non-trivial field of the
 * {@code src} object. However, you should never invoke it on the {@code src} object itself since that will cause an
 * infinite loop (Gson will call your call-back method again).
 *
 * @param src the object that needs to be converted to Json.
 * @param typeOfSrc the actual type (fully genericized version) of the source object.
 * @return a JsonElement corresponding to the specified object.
 */
@Override
public JsonElement serialize(ZonedDateTime src, Type typeOfSrc, JsonSerializationContext context) {
    return new JsonPrimitive(getFormatter().format(src));
}

From source file:com.fatboyindustrial.gsonjodatime.DateMidnightConverter.java

License:Open Source License

/**
 * Gson invokes this call-back method during serialization when it encounters a field of the
 * specified type. <p>/*from ww  w. ja v a 2s .  c om*/
 *
 * In the implementation of this call-back method, you should consider invoking
 * {@link com.google.gson.JsonSerializationContext#serialize(Object, java.lang.reflect.Type)} method to create JsonElements for any
 * non-trivial field of the {@code src} object. However, you should never invoke it on the
 * {@code src} object itself since that will cause an infinite loop (Gson will call your
 * call-back method again).
 *
 * @param src the object that needs to be converted to Json.
 * @param typeOfSrc the actual type (fully genericized version) of the source object.
 * @return a JsonElement corresponding to the specified object.
 */
@Override
public JsonElement serialize(DateMidnight src, Type typeOfSrc, JsonSerializationContext context) {
    final DateTimeFormatter fmt = ISODateTimeFormat.dateTime();
    return new JsonPrimitive(fmt.print(src));
}

From source file:com.fatboyindustrial.gsonjodatime.DateTimeConverter.java

License:Open Source License

/**
 * Gson invokes this call-back method during serialization when it encounters a field of the
 * specified type. <p>/*from   w w  w . j  a  v a  2s. c  o  m*/
 *
 * In the implementation of this call-back method, you should consider invoking
 * {@link JsonSerializationContext#serialize(Object, Type)} method to create JsonElements for any
 * non-trivial field of the {@code src} object. However, you should never invoke it on the
 * {@code src} object itself since that will cause an infinite loop (Gson will call your
 * call-back method again).
 *
 * @param src the object that needs to be converted to Json.
 * @param typeOfSrc the actual type (fully genericized version) of the source object.
 * @return a JsonElement corresponding to the specified object.
 */
@Override
public JsonElement serialize(DateTime src, Type typeOfSrc, JsonSerializationContext context) {
    final DateTimeFormatter fmt = ISODateTimeFormat.dateTime();
    return new JsonPrimitive(fmt.print(src));
}

From source file:com.fatboyindustrial.gsonjodatime.DurationConverter.java

License:Open Source License

/**
 * Gson invokes this call-back method during serialization when it encounters a field of the
 * specified type./*from ww w.  j a  v  a  2 s.  c o  m*/
 * <p>
 * In the implementation of this call-back method, you should consider invoking
 * {@link com.google.gson.JsonSerializationContext#serialize(Object, java.lang.reflect.Type)} method to create JsonElements for any
 * non-trivial field of the {@code src} object. However, you should never invoke it on the
 * {@code src} object itself since that will cause an infinite loop (Gson will call your
 * call-back method again).
 * @param src the object that needs to be converted to Json.
 * @param typeOfSrc the actual type (fully genericized version) of the source object.
 * @return a JsonElement corresponding to the specified object.
 */
@Override
public JsonElement serialize(Duration src, Type typeOfSrc, JsonSerializationContext context) {
    return new JsonPrimitive(src.toString());
}

From source file:com.fatboyindustrial.gsonjodatime.InstantConverter.java

License:Open Source License

@Override
public JsonElement serialize(Instant src, Type typeOfSrc, JsonSerializationContext context) {
    String value = fmt.print(src);

    return new JsonPrimitive(value);
}

From source file:com.fatboyindustrial.gsonjodatime.IntervalConverter.java

License:Open Source License

/**
 * Gson invokes this call-back method during serialization when it encounters a field of the
 * specified type. <p>//from  www. j a v a 2 s.  c o m
 *
 * In the implementation of this call-back method, you should consider invoking
 * {@link JsonSerializationContext#serialize(Object, Type)} method to create JsonElements for any
 * non-trivial field of the {@code src} object. However, you should never invoke it on the
 * {@code src} object itself since that will cause an infinite loop (Gson will call your
 * call-back method again).
 *
 * @param src the object that needs to be converted to Json.
 * @param typeOfSrc the actual type (fully genericized version) of the source object.
 * @return a JsonElement corresponding to the specified object.
 */
@Override
public JsonElement serialize(Interval src, Type typeOfSrc, JsonSerializationContext context) {
    return new JsonPrimitive(src.toString());
}

From source file:com.fatboyindustrial.gsonjodatime.LocalDateConverter.java

License:Open Source License

/**
 * Gson invokes this call-back method during serialization when it encounters a field of the
 * specified type. <p>/*from  ww  w. j a va 2s.  c  om*/
 *
 * In the implementation of this call-back method, you should consider invoking
 * {@link com.google.gson.JsonSerializationContext#serialize(Object, java.lang.reflect.Type)} method to create JsonElements for any
 * non-trivial field of the {@code src} object. However, you should never invoke it on the
 * {@code src} object itself since that will cause an infinite loop (Gson will call your
 * call-back method again).
 *
 * @param src the object that needs to be converted to Json.
 * @param typeOfSrc the actual type (fully genericized version) of the source object.
 * @return a JsonElement corresponding to the specified object.
 */
@Override
public JsonElement serialize(LocalDate src, Type typeOfSrc, JsonSerializationContext context) {
    final DateTimeFormatter fmt = DateTimeFormat.forPattern(PATTERN);
    return new JsonPrimitive(fmt.print(src));
}