List of usage examples for com.google.gson JsonSerializationContext serialize
public JsonElement serialize(Object src, Type typeOfSrc);
From source file:net.uiqui.couchdb.json.impl.SelectorSerializer.java
License:Apache License
private JsonElement serialize(final Operator operator, final Type typeOfSrc, final JsonSerializationContext context) { final JsonObject jsonObject = new JsonObject(); JsonElement element;/*from w w w.ja v a 2 s. com*/ if (operator.argument() instanceof Selector) { element = context.serialize(operator.argument(), typeOfSrc); } else { element = context.serialize(operator.argument()); } jsonObject.add(operator.operator(), element); return jsonObject; }
From source file:net.vpc.app.vainruling.core.service.util.DocumentSerializer.java
@Override public JsonElement serialize(Document src, Type typeOfSrc, JsonSerializationContext context) { return context.serialize(src.toMap(), Map.class); }
From source file:nz.ac.otago.psyanlab.common.model.util.AbsModelGsonAdapter.java
License:Open Source License
@Override public JsonElement serialize(T src, Type typeOfSrc, JsonSerializationContext jctx) { JsonObject r = new JsonObject(); r.add("type", new JsonPrimitive(src.getClass().getSimpleName())); r.add("properties", jctx.serialize(src, src.getClass())); return r;//from w ww. j a va 2 s. com }
From source file:org.apache.abdera2.activities.io.gson.BaseAdapter.java
License:Apache License
public JsonElement serialize(ASBase asbase, Type type, JsonSerializationContext context) { JsonObject el = new JsonObject(); for (String key : asbase) { Object val = asbase.getProperty(key); if (val != null) { JsonElement value = null;/*w ww . j a va 2s .c om*/ if (val instanceof Verb) value = context.serialize(val, Verb.class); else value = context.serialize(val, val.getClass()); el.add(key, value); } } return el; }
From source file:org.apache.abdera2.activities.io.gson.MultimapAdapter.java
License:Apache License
public JsonElement serialize(Multimap src, Type typeOfSrc, JsonSerializationContext context) { return context.serialize(src.asMap(), Map.class); }
From source file:org.apache.qpid.disttest.json.PropertyValueAdapter.java
License:Apache License
@Override public JsonElement serialize(PropertyValue src, Type typeOfSrc, JsonSerializationContext context) { if (src instanceof GeneratedPropertyValue) { JsonObject object = (JsonObject) context.serialize(src, Object.class); object.addProperty(DEF_FIELD, ((GeneratedPropertyValue) src).getDefinition()); return object; } else {/*from w w w . j a va2 s .c om*/ return context.serialize(src.getValue(), Object.class); } }
From source file:org.apache.tajo.catalog.json.TableMetaAdapter.java
License:Apache License
@Override public JsonElement serialize(TableMeta src, Type typeOfSrc, JsonSerializationContext context) { JsonObject jsonObj = new JsonObject(); jsonObj.addProperty("store", src.getStoreType().name()); jsonObj.add("options", context.serialize(src.getOptions(), KeyValueSet.class)); return jsonObj; }
From source file:org.apache.twill.internal.json.ILoggingEventSerializer.java
License:Apache License
@Override public JsonElement serialize(ILoggingEvent event, Type typeOfSrc, JsonSerializationContext context) { JsonObject json = new JsonObject(); json.addProperty("name", event.getLoggerName()); json.addProperty("host", hostname); json.addProperty("timestamp", Long.toString(event.getTimeStamp())); json.addProperty("level", event.getLevel().toString()); json.addProperty("className", classNameConverter.convert(event)); json.addProperty("method", methodConverter.convert(event)); json.addProperty("file", fileConverter.convert(event)); json.addProperty("line", lineConverter.convert(event)); json.addProperty("thread", event.getThreadName()); json.addProperty("message", event.getFormattedMessage()); json.addProperty("runnableName", runnableName); if (event.getThrowableProxy() == null) { json.add("throwable", JsonNull.INSTANCE); } else {//from ww w . j av a 2s . co m json.add("throwable", context.serialize(new DefaultLogThrowable(event.getThrowableProxy()), LogThrowable.class)); } return json; }
From source file:org.apache.twill.internal.json.LogThrowableCodec.java
License:Apache License
@Override public JsonElement serialize(LogThrowable throwable, Type typeOfSrc, JsonSerializationContext context) { JsonObject json = new JsonObject(); json.addProperty("className", throwable.getClassName()); json.addProperty("message", throwable.getMessage()); json.add("stackTraces", context.serialize(throwable.getStackTraces(), StackTraceElement[].class)); LogThrowable cause = throwable.getCause(); if (cause != null) { json.add("cause", context.serialize(cause, LogThrowable.class)); }//w w w . j av a 2s. c o m return json; }
From source file:org.apache.twill.internal.json.ResourceReportCodec.java
License:Apache License
@Override public JsonElement serialize(ResourceReport src, Type typeOfSrc, JsonSerializationContext context) { JsonObject json = new JsonObject(); json.addProperty("appMasterId", src.getApplicationId()); json.add("appMasterResources", context.serialize(src.getAppMasterResources(), new TypeToken<TwillRunResources>() { }.getType()));/*from w ww . j av a 2 s .c o m*/ json.add("runnableResources", context.serialize(src.getResources(), new TypeToken<Map<String, Collection<TwillRunResources>>>() { }.getType())); json.add("services", context.serialize(src.getServices(), new TypeToken<List<String>>() { }.getType())); return json; }