List of usage examples for com.google.gson JsonSerializationContext serialize
public JsonElement serialize(Object src, Type typeOfSrc);
From source file:org.redpin.server.standalone.json.BaseUserTypeAdapter.java
License:Open Source License
/** * @see JsonSerializer#serialize(Object, Type, JsonSerializationContext) */// ww w . j a va 2s . c om @Override public JsonElement serialize(org.redpin.base.core.User src, Type typeOfSrc, JsonSerializationContext context) { return context.serialize(src, User.class); }
From source file:org.xacml4j.v30.marshal.json.ObligationOrAdviceAdapter.java
License:Open Source License
@Override public JsonElement serialize(BaseDecisionRuleResponse src, Type typeOfSrc, JsonSerializationContext context) { JsonObject o = new JsonObject(); o.addProperty(ID_PROPERTY, src.getId()); Collection<AttributeAssignment> attributeAssignments = src.getAttributes(); if (attributeAssignments != null && !attributeAssignments.isEmpty()) { o.add(ATTRIBUTE_ASSIGNMENTS_PROPERTY, context.serialize(attributeAssignments, ATTRIBUTE_ASSIGNMENTS_TYPE)); }//from www .j a v a 2 s .c om return o; }
From source file:se.kth.infosys.login.couchbase.AbstractRegisteredServiceJsonSerializer.java
License:Apache License
/** * @param src CAS Service.//from w w w . j av a 2 s .c om * @param typeOfSrc (ignored). * @param context Gson serialization context. * @see JsonSerializer#serialize(Object, Type, JsonSerializationContext) * @return JSON serialized version of a CAS service. */ public final JsonElement serialize(final AbstractRegisteredService src, final Type typeOfSrc, final JsonSerializationContext context) { JsonObject result = new JsonObject(); result.add("type", new JsonPrimitive(src.getClass().getName())); result.add("properties", context.serialize(src, src.getClass())); return result; }
From source file:syncthing.api.model.VersioningTypeConverter.java
License:Mozilla Public License
@Override public JsonElement serialize(Versioning src, Type typeOfSrc, JsonSerializationContext context) { JsonObject obj = new JsonObject(); JsonElement type = context.serialize(src.type, VersioningType.class); obj.add("type", type); JsonElement params;//from ww w . j a v a2 s . c o m switch (src.type) { case EXTERNAL: params = context.serialize(src.params, VersioningExternal.Params.class); break; case SIMPLE: params = context.serialize(src.params, VersioningSimple.Params.class); break; case STAGGERED: params = context.serialize(src.params, VersioningStaggered.Params.class); break; case TRASHCAN: params = context.serialize(src.params, VersioningTrashCan.Params.class); break; case NONE: default: params = null;//context.serialize(src.params, VersioningNone.Params.class); break; } obj.add("params", params); return obj; }
From source file:tajo.engine.json.EvalNodeAdapter.java
License:Apache License
@Override public JsonElement serialize(EvalNode evalNode, Type type, JsonSerializationContext ctx) { JsonObject json = new JsonObject(); json.add("type", new JsonPrimitive(evalNode.getClass().getName())); json.add("properties", ctx.serialize(evalNode, evalNode.getClass())); return json;//from ww w .j a v a2s.com }
From source file:uk.co.thinkofdeath.prismarine.chat.ComponentSerializer.java
License:Apache License
@Override public JsonElement serialize(Component component, Type type, JsonSerializationContext jsonSerializationContext) { if (component instanceof TextComponent && !component.hasFormatting()) { return new JsonPrimitive(((TextComponent) component).getText()); }// w ww .j a va 2 s. c o m JsonObject jsonObject = new JsonObject(); if (component instanceof TextComponent) { jsonObject.addProperty("text", ((TextComponent) component).getText()); } if (component.bold != null) { jsonObject.addProperty("bold", component.bold); } if (component.italic != null) { jsonObject.addProperty("italic", component.italic); } if (component.underlined != null) { jsonObject.addProperty("underlined", component.underlined); } if (component.strikethrough != null) { jsonObject.addProperty("strikethrough", component.strikethrough); } if (component.obfuscated != null) { jsonObject.addProperty("obfuscated", component.obfuscated); } if (component.color != null) { jsonObject.addProperty("color", component.color.toString().toLowerCase()); } if (component.subComponents != null) { JsonArray array = new JsonArray(); for (Component c : component.subComponents) { array.add(jsonSerializationContext.serialize(c, Component.class)); } jsonObject.add("extra", array); } return jsonObject; }