List of usage examples for com.google.gson JsonSerializationContext serialize
public JsonElement serialize(Object src);
From source file:com.claresco.tinman.json.XapiActorJson.java
License:Open Source License
@Override public JsonElement serialize(XapiActor arg0, Type arg1, JsonSerializationContext arg2) { return arg2.serialize(arg0); }
From source file:com.claresco.tinman.json.XapiAgentJson.java
License:Open Source License
@Override public JsonElement serialize(XapiAgent arg0, Type arg1, JsonSerializationContext arg2) { JsonObject result = new JsonObject(); if (arg0.hasName()) { result.addProperty("name", arg0.getName()); }//from www . ja v a2s.c o m result.addProperty("objectType", arg0.getObjectType()); XapiInverseFunctionalIdentifier theIdentifier = arg0.getInverseFuncId(); if (theIdentifier.hasMbox()) { result.addProperty("mbox", theIdentifier.getMbox().toString()); } if (theIdentifier.hasMboxSha1Sum()) { result.addProperty("mbox_sha1sum", theIdentifier.getMboxSha1Sum()); } if (theIdentifier.hasOpenId()) { result.addProperty("openid", theIdentifier.getOpenId().toString()); } if (theIdentifier.hasAccount()) { result.add("account", arg2.serialize(theIdentifier.getAccount())); } return result; }
From source file:com.claresco.tinman.json.XapiContextActivitiesJson.java
License:Open Source License
@Override public JsonElement serialize(XapiContextActivities arg0, Type arg1, JsonSerializationContext arg2) { JsonObject result = new JsonObject(); JsonArray theParentArray = new JsonArray(); if (arg0.hasParent()) { for (XapiActivity activity : arg0.getParent()) { theParentArray.add(arg2.serialize(activity)); }/*w w w .j a va 2 s . c o m*/ result.add("parent", theParentArray); } JsonArray theGroupingArray = new JsonArray(); if (arg0.hasGrouping()) { for (XapiActivity activity : arg0.getGrouping()) { theGroupingArray.add(arg2.serialize(activity)); } result.add("grouping", theGroupingArray); } if (arg0.hasCategory()) { JsonArray theCategoryArray = serialize(arg0.getCategory(), arg2); if (theCategoryArray != null) { result.add("category", theCategoryArray); } } if (arg0.hasOther()) { JsonArray theOtherArray = serialize(arg0.getOther(), arg2); if (theOtherArray != null) { result.add("other", theOtherArray); } } return result; }
From source file:com.claresco.tinman.json.XapiGroupJson.java
License:Open Source License
@Override public JsonElement serialize(XapiGroup arg0, Type arg1, JsonSerializationContext arg2) { JsonObject result = new JsonObject(); result.addProperty("name", arg0.getName()); result.addProperty("objectType", arg0.getObjectType()); XapiInverseFunctionalIdentifier theIdentifier = arg0.getInverseFuncId(); if (theIdentifier.hasMbox()) { result.addProperty("mbox", theIdentifier.getMbox().toString()); }//from ww w . j ava 2 s . c o m result.addProperty("mbox_sha1sum", theIdentifier.getMboxSha1Sum()); if (theIdentifier.hasOpenId()) { result.addProperty("openid", theIdentifier.getOpenId().toString()); } result.add("account", arg2.serialize(theIdentifier.getAccount())); // Iterate through the member to create a jsonarray JsonArray memberArray = new JsonArray(); for (XapiAgent a : arg0.getMember()) { memberArray.add(arg2.serialize(a)); } result.add("member", memberArray); return result; }
From source file:com.claresco.tinman.json.XapiInteractionComponentJson.java
License:Open Source License
@Override public JsonElement serialize(XapiInteractionComponent arg0, Type arg1, JsonSerializationContext arg2) { if (arg0.isEmpty()) { return null; }//from ww w. j av a 2 s . c om JsonObject result = new JsonObject(); result.addProperty("id", arg0.getID()); if (arg0.hasDescription()) { result.add("description", arg2.serialize(arg0.getDescription())); } return result; }
From source file:com.claresco.tinman.json.XapiInverseFuncIdJson.java
License:Open Source License
@Override public JsonElement serialize(XapiInverseFunctionalIdentifier arg0, Type arg1, JsonSerializationContext arg2) { JsonObject result = new JsonObject(); if (arg0.hasMbox()) { result.addProperty("mbox", arg0.getMbox().toString()); }//from ww w . j av a 2 s . c om result.addProperty("mbox_sha1sum", arg0.getMboxSha1Sum()); if (arg0.hasOpenId()) { result.addProperty("openid", arg0.getOpenId().toString()); } result.add("account", arg2.serialize(arg0.getAccount())); return result; }
From source file:com.claresco.tinman.json.XapiStatementJson.java
License:Open Source License
@Override public JsonElement serialize(XapiStatement arg0, Type arg1, JsonSerializationContext arg2) { JsonObject result = new JsonObject(); result.addProperty("id", arg0.getId()); result.add("actor", arg2.serialize(arg0.getActor())); result.add("verb", arg2.serialize(arg0.getVerb())); result.add("object", arg2.serialize(arg0.getObject())); if (arg0.hasResult()) { result.add("result", arg2.serialize(arg0.getResult())); }/*w w w . j a v a 2 s . co m*/ if (arg0.hasContext()) { result.add("context", arg2.serialize(arg0.getContext())); } if (arg0.hasTimeStamp()) { result.addProperty("timestamp", arg0.getTimeStampAsString()); } return result; }
From source file:com.claresco.tinman.json.XapiSubStatementJson.java
License:Open Source License
@Override public JsonElement serialize(XapiSubStatement arg0, Type arg1, JsonSerializationContext arg2) { JsonObject result = new JsonObject(); result.add("actor", arg2.serialize(arg0.getActor())); result.add("verb", arg2.serialize(arg0.getVerb())); result.add("object", arg2.serialize(arg0.getObject())); return result; }
From source file:com.cloud.api.IdentityTypeAdapter.java
License:Apache License
@Override public JsonElement serialize(IdentityProxy src, Type srcType, JsonSerializationContext context) { if (SerializationContext.current().getUuidTranslation()) { assert (src != null); if (src.getValue() == null) return context.serialize(null); IdentityDao identityDao = new IdentityDaoImpl(); if (src.getTableName() != null) { String uuid = identityDao.getIdentityUuid(src.getTableName(), String.valueOf(src.getValue())); if (uuid == null) return context.serialize(null); // Exceptions set the _idFieldName in the IdentityProxy structure. So if this field is not // null, prepare a structure of uuid and idFieldName and return the json representation of that. String idName = src.getidFieldName(); if (idName != null) { // Prepare a structure. JsonObject jsonObj = new JsonObject(); jsonObj.add("uuid", new JsonPrimitive(uuid)); jsonObj.add("uuidProperty", new JsonPrimitive(idName)); return jsonObj; }/* w ww.j ava2 s .co m*/ return new JsonPrimitive(uuid); } else { return new JsonPrimitive(String.valueOf(src.getValue())); } } else { return new Gson().toJsonTree(src); } }
From source file:com.codereligion.bugsnag.logback.resource.MetaDataVOSerializer.java
License:Apache License
@Override public JsonElement serialize(final MetaDataVO src, final Type typeOfSrc, final JsonSerializationContext context) { return context.serialize(src.getTabsByName()); }