List of usage examples for com.google.gson JsonSerializationContext serialize
public JsonElement serialize(Object src, Type typeOfSrc);
From source file:bootwildfly.ProblemaJsonSerializer.java
@Override public JsonElement serialize(Problema p, Type type, JsonSerializationContext jsc) { //jsc.serialize() JsonObject object = new JsonObject(); TypeToken<List<Teste>> typeTestes = new TypeToken<List<Teste>>() { };//from ww w .j av a 2 s. c om JsonElement sumario = jsc.serialize(p.getSumario(), SumarioDeProblema.class); JsonElement testes = jsc.serialize(p.getTeste()); object.addProperty("id", p.getId()); object.addProperty("dica", p.getDica()); object.addProperty("isPublicado", p.isIsPublicado()); object.addProperty("isPublicado", p.isIsPublicado()); object.add("sumario", sumario); object.add("teste", testes); return object; }
From source file:ca.ualberta.cs.unter.util.GeoPointConverter.java
License:Apache License
@Override public JsonElement serialize(GeoPoint src, Type srcType, JsonSerializationContext context) { JsonArray array = new JsonArray(); array.add(context.serialize(src.getLongitudeE6() / 1E6, Double.class)); array.add(context.serialize(src.getLatitudeE6() / 1E6, Double.class)); return array; }
From source file:cc.kave.commons.utils.json.legacy.MultimapTypeAdapter.java
License:Open Source License
@Override public JsonElement serialize(final Multimap src, final Type typeOfSrc, final JsonSerializationContext context) { return context.serialize(src.asMap(), createMapType(typeOfSrc)); }
From source file:cc.kave.commons.utils.json.legacy.ObjectUsageFeatureRedirector.java
License:Open Source License
@Override public JsonElement serialize(T src, Type typeOfSrc, JsonSerializationContext context) { return context.serialize(src, UsageFeature.class); }
From source file:co.aurasphere.botmill.fb.internal.util.json.ButtonSerializer.java
License:Open Source License
public JsonElement serialize(Button src, Type typeOfSrc, JsonSerializationContext context) { ButtonType buttonType = src.getType(); Class<?> buttonClass = getButtonClass(buttonType); return context.serialize(src, buttonClass); }
From source file:co.cask.cdap.common.zookeeper.coordination.ResourceAssignmentTypeAdapter.java
License:Apache License
@Override public JsonElement serialize(ResourceAssignment src, Type typeOfSrc, JsonSerializationContext context) { JsonObject json = new JsonObject(); json.addProperty("name", src.getName()); src.getAssignments().entries();//ww w . j a v a2s .c o m JsonArray assignments = new JsonArray(); for (Map.Entry<Discoverable, PartitionReplica> entry : src.getAssignments().entries()) { JsonArray entryJson = new JsonArray(); entryJson.add(context.serialize(entry.getKey(), Discoverable.class)); entryJson.add(context.serialize(entry.getValue())); assignments.add(entryJson); } json.add("assignments", assignments); return json; }
From source file:co.cask.cdap.internal.app.AbstractSpecificationCodec.java
License:Apache License
protected final <V> JsonElement serializeMap(Map<String, V> map, JsonSerializationContext context, Class<V> valueType) { Type type = new TypeToken<Map<String, V>>() { }.where(new TypeParameter<V>() { }, valueType).getType();/*from w ww . ja va2 s . co m*/ return context.serialize(map, type); }
From source file:co.cask.cdap.internal.app.AbstractSpecificationCodec.java
License:Apache License
protected final <V> JsonElement serializeSet(Set<V> set, JsonSerializationContext context, Class<V> valueType) { Type type = new TypeToken<Set<V>>() { }.where(new TypeParameter<V>() { }, valueType).getType();/*from w w w .ja va 2s . c o m*/ return context.serialize(set, type); }
From source file:co.cask.cdap.internal.app.AbstractSpecificationCodec.java
License:Apache License
protected final <V> JsonElement serializeList(List<V> list, JsonSerializationContext context, Class<V> valueType) { Type type = new TypeToken<List<V>>() { }.where(new TypeParameter<V>() { }, valueType).getType();//from w w w .j a v a 2 s.co m return context.serialize(list, type); }
From source file:co.cask.cdap.internal.app.FlowletSpecificationCodec.java
License:Apache License
@Override public JsonElement serialize(FlowletSpecification src, Type typeOfSrc, JsonSerializationContext context) { JsonObject jsonObj = new JsonObject(); jsonObj.add("className", new JsonPrimitive(src.getClassName())); jsonObj.add("name", new JsonPrimitive(src.getName())); jsonObj.add("description", new JsonPrimitive(src.getDescription())); jsonObj.add("failurePolicy", new JsonPrimitive(src.getFailurePolicy().name())); jsonObj.add("datasets", serializeSet(src.getDataSets(), context, String.class)); jsonObj.add("properties", serializeMap(src.getProperties(), context, String.class)); jsonObj.add("resources", context.serialize(src.getResources(), new TypeToken<ResourceSpecification>() { }.getType()));/*from w w w.ja v a2 s . c o m*/ return jsonObj; }