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);

Source Link

Document

Invokes default serialization on the specified object.

Usage

From source file:de.winniehell.battlebeavers.storage.SoldierSerializer.java

License:Open Source License

@Override
public JsonElement serialize(final Soldier pSrc, final Type pType, final JsonSerializationContext pContext) {
    if (pSrc == null) {
        return JsonNull.INSTANCE;
    }/* w  w w. jav a2 s .co  m*/

    final JsonObject object = new JsonObject();

    object.add("id", pContext.serialize(pSrc.getId()));
    object.add("team", pContext.serialize(pSrc.getTeam()));
    object.add("tile", pContext.serialize(pSrc.getTile()));
    object.add("view_angle", pContext.serialize(pSrc.getRotation()));
    object.add("waypoints", pContext.serialize(pSrc.getWaypoints()));
    object.add("hp", pContext.serialize(pSrc.getHP()));

    return object;
}

From source file:de.winniehell.battlebeavers.storage.StepSerializer.java

License:Open Source License

@Override
public JsonElement serialize(final Step pSrc, final Type pType, final JsonSerializationContext pContext) {
    if (pSrc == null) {
        return JsonNull.INSTANCE;
    }//from  ww w . j  ava2 s  . co  m

    final JsonArray array = new JsonArray();

    array.add(pContext.serialize(pSrc.getTileColumn()));
    array.add(pContext.serialize(pSrc.getTileRow()));

    return array;
}

From source file:de.winniehell.battlebeavers.storage.TileSerializer.java

License:Open Source License

@Override
public JsonElement serialize(final Tile pSrc, final Type pType, final JsonSerializationContext pContext) {
    if (pSrc == null) {
        return JsonNull.INSTANCE;
    }//from www  . ja  v a 2 s. co  m

    final JsonArray array = new JsonArray();

    array.add(pContext.serialize(pSrc.getColumn()));
    array.add(pContext.serialize(pSrc.getRow()));

    return array;
}

From source file:de.winniehell.battlebeavers.storage.WayPointSerializer.java

License:Open Source License

@Override
public JsonElement serialize(final WayPoint pSrc, final Type pType, final JsonSerializationContext pContext) {
    if (pSrc == null) {
        return JsonNull.INSTANCE;
    }//from   w  ww.jav  a  2  s .c o  m

    final JsonObject object = new JsonObject();

    object.add("path", pContext.serialize(pSrc.getPath()));
    object.add("tile", pContext.serialize(pSrc.getTile()));

    if (pSrc.getAim() == null) {
        object.add("aim", JsonNull.INSTANCE);
    } else {
        object.add("aim", pContext.serialize(pSrc.getAim().getTile()));
    }

    if (pSrc.getWait() > 0) {
        object.addProperty("wait", pSrc.getWait());
    }

    return object;
}

From source file:de.winniehell.battlebeavers.storage.WeightedPathSerializer.java

License:Open Source License

@Override
public JsonElement serialize(final WeightedPath pSrc, final Type pType,
        final JsonSerializationContext pContext) {
    if (pSrc == null) {
        return JsonNull.INSTANCE;
    }// ww w.j  a  v a 2  s.com

    final JsonArray array = new JsonArray();

    for (int i = 0; i < pSrc.getLength(); ++i) {
        array.add(pContext.serialize(pSrc.getStep(i)));
    }

    return array;
}

From source file:edu.eci.arsw.umlcolaborativo.util.InterfaceAdapter.java

@Override
public JsonElement serialize(T object, Type interfaceType, JsonSerializationContext context) {
    final JsonObject wrapper = new JsonObject();
    wrapper.addProperty("type", object.getClass().getName());
    //Gson gson = new Gson();
    //wrapper.add("data", gson.toJsonTree(object, interfaceType));
    wrapper.add("data", context.serialize(object));
    return wrapper;
}

From source file:edu.isi.wings.portal.classes.JsonHandler.java

License:Apache License

public JsonElement serialize(Node node, Type typeOfSrc, JsonSerializationContext context) {
    JsonObject obj = new JsonObject();
    obj.addProperty("comment", node.getComment());
    obj.addProperty("id", node.getID());
    obj.add("componentVariable", context.serialize(node.getComponentVariable()));
    obj.add("prule", context.serialize(node.getPortSetRule()));
    obj.add("crule", context.serialize(node.getComponentSetRule()));
    return obj;// w ww .j  a  va 2 s.  c o m
}

From source file:edu.isi.wings.portal.classes.JsonHandler.java

License:Apache License

public JsonElement serialize(SetExpression expr, Type typeOfSrc, JsonSerializationContext context) {
    if (expr.isSet()) {
        JsonObject obj = new JsonObject();
        obj.add("op", context.serialize(expr.getOperator()));
        JsonArray arr = new JsonArray();
        for (SetExpression s : expr) {
            arr.add(context.serialize(s));
        }/*from ww w . j  a  v a2  s. c  o m*/
        obj.add("args", arr);
        return obj;
    } else {
        if (expr.getPort() != null)
            return context.serialize(expr.getPort().getID());
        else
            return null;
    }
}

From source file:edu.isi.wings.portal.classes.JsonHandler.java

License:Apache License

public JsonElement serialize(Date date, Type typeOfSrc, JsonSerializationContext context) {
    return context.serialize(date.getTime() / 1000);
}

From source file:gov.va.isaac.util.json.InterfaceAdapter.java

License:Apache License

public JsonElement serialize(T object, Type interfaceType, JsonSerializationContext context) {
    final JsonObject wrapper = new JsonObject();
    wrapper.addProperty("type", object.getClass().getName());
    wrapper.add("data", context.serialize(object));
    return wrapper;
}