Example usage for com.google.gson JsonSerializationContext serialize

List of usage examples for com.google.gson JsonSerializationContext serialize

Introduction

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

Prototype

public JsonElement serialize(Object src, Type typeOfSrc);

Source Link

Document

Invokes default serialization on the specified object passing the specific type information.

Usage

From source file:org.primefaces.extensions.renderkit.layout.LayoutOptionsSerializer.java

License:Apache License

public JsonElement serialize(LayoutOptions src, Type typeOfSrc, JsonSerializationContext context) {
    JsonObject result = new JsonObject();

    Set<Map.Entry<String, Object>> options = src.getOptions().entrySet();
    for (Map.Entry<String, Object> entry : options) {
        Object value = entry.getValue();
        JsonPrimitive jsonPrimitive = null;

        if (value instanceof Boolean) {
            jsonPrimitive = new JsonPrimitive((Boolean) value);
        } else if (value instanceof Number) {
            jsonPrimitive = new JsonPrimitive((Number) value);
        } else if (value instanceof String) {
            jsonPrimitive = new JsonPrimitive((String) value);
        }/*from   w  ww. j a v  a 2s  .co  m*/

        result.add(entry.getKey(), jsonPrimitive);
    }

    if (src.getPanesOptions() != null) {
        result.add("panes", context.serialize(src.getPanesOptions(), src.getPanesOptions().getClass()));
    }

    if (src.getNorthOptions() != null) {
        result.add("north", context.serialize(src.getNorthOptions(), src.getNorthOptions().getClass()));
    }

    if (src.getSouthOptions() != null) {
        result.add("south", context.serialize(src.getSouthOptions(), src.getSouthOptions().getClass()));
    }

    if (src.getWestOptions() != null) {
        result.add("west", context.serialize(src.getWestOptions(), src.getWestOptions().getClass()));
    }

    if (src.getEastOptions() != null) {
        result.add("east", context.serialize(src.getEastOptions(), src.getEastOptions().getClass()));
    }

    if (src.getCenterOptions() != null) {
        result.add("center", context.serialize(src.getCenterOptions(), src.getCenterOptions().getClass()));
    }

    if (src.getChildOptions() != null) {
        result.add("childOptions", context.serialize(src.getChildOptions(), src.getChildOptions().getClass()));
    }

    return result;
}

From source file:org.redpin.android.json.BaseSpinnerDataTypeAdapter.java

License:Open Source License

/**
 * @see JsonSerializer#serialize(Object, Type, JsonSerializationContext)
 *///from  www. ja va 2s . com
public JsonElement serialize(org.redpin.base.core.SpinnerData src, Type typeOfSrc,
        JsonSerializationContext context) {
    return context.serialize(src, SpinnerData.class);
}

From source file:org.redpin.android.json.BaseUserTypeAdapter.java

License:Open Source License

/**
 * @see JsonSerializer#serialize(Object, Type, JsonSerializationContext)
 *//*from   ww  w .  j ava 2s  .c  o m*/
public JsonElement serialize(org.redpin.base.core.User src, Type typeOfSrc, JsonSerializationContext context) {
    return context.serialize(src, User.class);
}

From source file:org.redpin.server.standalone.json.BaseFingerprintTypeAdapter.java

License:Open Source License

/**
 * @see JsonSerializer#serialize(Object, Type, JsonSerializationContext)
 *//*  w w  w.j a  v a  2s  . c o m*/
@Override
public JsonElement serialize(org.redpin.base.core.Fingerprint src, Type typeOfSrc,
        JsonSerializationContext context) {
    return context.serialize(src, Fingerprint.class);
}

From source file:org.redpin.server.standalone.json.BaseHistoryTypeAdapter.java

License:Open Source License

/**
 * @see JsonSerializer#serialize(Object, Type, JsonSerializationContext)
 *///  www  . jav  a 2  s  .com
@Override
public JsonElement serialize(org.redpin.base.core.History src, Type typeOfSrc,
        JsonSerializationContext context) {
    return context.serialize(src, History.class);
}

From source file:org.redpin.server.standalone.json.BaseLocationTypeAdapter.java

License:Open Source License

/**
 * @see JsonSerializer#serialize(Object, Type, JsonSerializationContext)
 *//*from  ww  w . j av a  2s.c o m*/
@Override
public JsonElement serialize(org.redpin.base.core.Location src, Type typeOfSrc,
        JsonSerializationContext context) {

    return context.serialize(src, Location.class);
}

From source file:org.redpin.server.standalone.json.BaseMapTypeAdapter.java

License:Open Source License

/**
 * @see JsonSerializer#serialize(Object, Type, JsonSerializationContext)
 *//*www.  jav  a 2 s.co m*/
@Override
public JsonElement serialize(org.redpin.base.core.Map src, Type typeOfSrc, JsonSerializationContext context) {
    return context.serialize(src, Map.class);
}

From source file:org.redpin.server.standalone.json.BaseMeasurementTypeAdapter.java

License:Open Source License

/**
 * @see JsonSerializer#serialize(Object, Type, JsonSerializationContext)
 *///w w  w  .j  av a2s .  co  m
@Override
public JsonElement serialize(org.redpin.base.core.Measurement src, Type typeOfSrc,
        JsonSerializationContext context) {

    return context.serialize(src, Measurement.class);
}

From source file:org.redpin.server.standalone.json.BaseSpinnerDataTypeAdapter.java

License:Open Source License

/**
 * @see JsonSerializer#serialize(Object, Type, JsonSerializationContext)
 *///from w  ww  . j  a va2  s .c o m
@Override
public JsonElement serialize(org.redpin.base.core.SpinnerData src, Type typeOfSrc,
        JsonSerializationContext context) {
    return context.serialize(src, SpinnerData.class);
}

From source file:org.redpin.server.standalone.json.BaseTaskTypeAdapter.java

License:Open Source License

/**
 * @see JsonSerializer#serialize(Object, Type, JsonSerializationContext)
 */// w  ww . j a va2  s.co m
@Override
public JsonElement serialize(org.redpin.base.core.Task src, Type typeOfSrc, JsonSerializationContext context) {
    return context.serialize(src, Task.class);
}