List of usage examples for com.google.gson JsonSerializationContext serialize
public JsonElement serialize(Object src);
From source file:org.helios.apmrouter.dataservice.json.marshalling.encoders.IMetricSerializer.java
License:Open Source License
/** * {@inheritDoc}/* w w w.ja v a 2s. co m*/ * @see com.google.gson.JsonSerializer#serialize(java.lang.Object, java.lang.reflect.Type, com.google.gson.JsonSerializationContext) */ @Override public JsonElement serialize(IMetric src, Type typeOfSrc, JsonSerializationContext context) { JsonObject jo = new JsonObject(); jo.addProperty("agent", src.getAgent()); jo.addProperty("host", src.getHost()); jo.addProperty("fqn", src.getFQN()); jo.addProperty("name", src.getName()); jo.addProperty("typename", src.getType().name()); jo.addProperty("typeid", src.getType().ordinal()); jo.addProperty("time", src.getTime()); jo.addProperty("id", src.getToken()); jo.add("fqn", context.serialize(src.getValue())); return jo; }
From source file:org.immutables.mongo.fixture.holder.HolderJsonSerializer.java
License:Apache License
@Override public JsonElement serialize(Holder src, Type type, JsonSerializationContext context) { JsonObject root = new JsonObject(); JsonElement value = context.serialize(src.value()); root.addProperty("id", src.id()); if (value.isJsonObject()) { value.getAsJsonObject().addProperty(Holder.TYPE_PROPERTY, src.value().getClass().getName()); }//from w ww . ja v a 2 s . c om root.add(VALUE_PROPERTY, value); return root; }
From source file:org.jeeventstore.serialization.gson.EventListTypeConverter.java
License:Open Source License
@Override public JsonElement serialize(EventList src, Type srcType, JsonSerializationContext context) { JsonObject combined = new JsonObject(); combined.add("version", new JsonPrimitive(1)); JsonArray events = new JsonArray(); for (Serializable s : src.events()) { JsonObject obj = new JsonObject(); obj.add("type", new JsonPrimitive(s.getClass().getCanonicalName())); obj.add("body", context.serialize(s)); events.add(obj);//www .j a v a 2s. c o m } combined.add("events", events); return combined; }
From source file:org.kairosdb.client.serializer.DataPointSerializer.java
License:Apache License
@Override public JsonElement serialize(DataPoint src, Type typeOfSrc, JsonSerializationContext context) { JsonArray array = new JsonArray(); array.add(new JsonPrimitive(src.getTimestamp())); array.add(context.serialize(src.getValue())); return array; }
From source file:org.kurento.modulecreator.json.DataItemAdapter.java
License:Apache License
@Override public JsonElement serialize(DataItem src, Type typeOfSrc, JsonSerializationContext context) { JsonObject object = new JsonObject(); if (src.getName() != null) { object.add("name", context.serialize(src.getName())); }/*from www . jav a2 s .c om*/ if (src.getDoc() != null) { object.addProperty("doc", src.getDoc()); } if (src.getType() != null) { object.add("type", context.serialize(src.getType())); } if (src.isOptional()) { object.addProperty("optional", src.isOptional()); if (src.getDefaultValue() != null) { object.add("defaultValue", src.getDefaultValue()); } } if (src instanceof Property) { Property prop = (Property) src; if (prop.isReadOnly()) { object.addProperty("readOnly", true); } if (prop.isFinal()) { object.addProperty("final", true); } } return object; }
From source file:org.kurento.modulecreator.json.MethodAdapter.java
License:Apache License
@Override public JsonElement serialize(Method src, Type typeOfSrc, JsonSerializationContext context) { JsonObject object = new JsonObject(); if (src.getName() != null) { object.addProperty("name", src.getName()); }/*from ww w .j a v a 2 s.co m*/ if (src.getParams() != null) { object.add("params", context.serialize(src.getParams())); } if (src.getReturn() != null) { object.add("return", context.serialize(src.getReturn())); } return object; }
From source file:org.kurento.modulecreator.json.RemoteClassAdapter.java
License:Apache License
@Override public JsonElement serialize(RemoteClass src, Type typeOfSrc, JsonSerializationContext context) { JsonObject object = new JsonObject(); if (src.getName() != null) { object.addProperty("name", src.getName()); }//from w ww . ja va2s .c om if (src.getDoc() != null) { object.addProperty("doc", src.getDoc()); } if (src.isAbstract()) { object.add("abstract", new JsonPrimitive(true)); } if (src.getExtends() != null) { object.add("extends", context.serialize(src.getExtends())); } if (src.getConstructor() != null) { object.add("constructor", context.serialize(src.getConstructor())); } if (!src.getProperties().isEmpty()) { object.add("properties", context.serialize(src.getProperties())); } if (!src.getMethods().isEmpty()) { object.add("methods", context.serialize(src.getMethods())); } if (!src.getEvents().isEmpty()) { object.add("events", context.serialize(src.getEvents())); } return object; }
From source file:org.lanternpowered.server.script.function.action.json.ConditionalActionJsonSerializer.java
License:MIT License
@Override public JsonElement serialize(ConditionalAction src, Type typeOfSrc, JsonSerializationContext context) { final JsonObject json = new JsonObject(); json.add(CONDITION, context.serialize(src.getCondition())); json.add(ACTION, context.serialize(src.getAction())); return json;//from w ww . jav a2 s .c o m }
From source file:org.lanternpowered.server.script.function.action.json.MultiActionJsonSerializer.java
License:MIT License
@Override public JsonElement serialize(MultiAction src, Type typeOfSrc, JsonSerializationContext context) { final List<Action> actions = src.getActions(); return context.serialize(actions.size() == 1 ? actions.get(0) : actions); }
From source file:org.lanternpowered.server.script.function.condition.json.AndConditionJsonSerializer.java
License:MIT License
@Override public JsonElement serialize(AndCondition src, Type typeOfSrc, JsonSerializationContext context) { return context.serialize(src.getConditions()); }