List of usage examples for com.google.gson JsonSerializationContext serialize
public JsonElement serialize(Object src, Type typeOfSrc);
From source file:com.berniesanders.fieldthebern.parsing.CollectionDeserializer.java
License:Apache License
@Override public JsonElement serialize(ApiItem src, Type typeOfSrc, JsonSerializationContext context) { if ("collection".equals(src.getType())) { return context.serialize(src, Collection.class); } else { //("page".equals(type)) return context.serialize(src, Page.class); }/*from w w w . ja v a 2 s . co m*/ }
From source file:com.claresco.tinman.json.XapiActivityDefinitionJson.java
License:Open Source License
@Override public JsonElement serialize(XapiActivityDefinition arg0, Type arg1, JsonSerializationContext arg2) { if (arg0.isEmpty()) { return null; }//from w w w.j a v a 2 s . c om JsonObject result = new JsonObject(); if (arg0.hasName()) { result.add("name", arg2.serialize(arg0.getName(), XapiLanguageMap.class)); } if (arg0.hasDescription()) { result.add("description", arg2.serialize(arg0.getDescription(), XapiLanguageMap.class)); } if (arg0.hasType()) { result.addProperty("type", arg0.getType().toString()); } if (arg0.hasInteractionProperties()) { XapiInteraction theInteraction = arg0.getInteractionProperties(); if (theInteraction.hasChoices()) { result.add("choices", JsonUtility.jsonArrayFromXapiInteractionComponent(theInteraction.getChoices(), arg2)); } if (theInteraction.hasScale()) { result.add("scale", JsonUtility.jsonArrayFromXapiInteractionComponent(theInteraction.getScale(), arg2)); } if (theInteraction.hasTarget()) { result.add("target", JsonUtility.jsonArrayFromXapiInteractionComponent(theInteraction.getTarget(), arg2)); } if (theInteraction.hasSource()) { result.add("source", JsonUtility.jsonArrayFromXapiInteractionComponent(theInteraction.getSource(), arg2)); } if (theInteraction.hasSteps()) { result.add("steps", JsonUtility.jsonArrayFromXapiInteractionComponent(theInteraction.getSteps(), arg2)); } if (theInteraction.hasCorrectReponse()) { ArrayList<String> theCorrectResponses = theInteraction.getCorrectResponse(); JsonArray theCorrectResponseArray = new JsonArray(); for (String correctResponse : theCorrectResponses) { theCorrectResponseArray.add(new JsonPrimitive(correctResponse)); } result.add("correctResponsesPattern", theCorrectResponseArray); } if (theInteraction.hasType()) { result.addProperty("interactionType", theInteraction.getType()); } } if (arg0.hasExtension()) { XapiExtension theExt = arg0.getExtension(); JsonObject theExtJson = new JsonObject(); for (String key : theExt.getKeys()) { theExtJson.addProperty(key, theExt.getValueOf(key)); } result.add("extensions", theExtJson); } return result; }
From source file:com.claresco.tinman.json.XapiActivityJson.java
License:Open Source License
@Override public JsonElement serialize(XapiActivity arg0, Type arg1, JsonSerializationContext arg2) { JsonObject result = new JsonObject(); result.addProperty("id", arg0.getId().toString()); result.addProperty("objectType", arg0.getObjectType()); JsonElement theDefinition = arg2.serialize(arg0.getDefinition(), XapiActivityDefinition.class); if (theDefinition != null) { result.add("definition", theDefinition); }// w w w .j a v a2 s . c om return result; }
From source file:com.claresco.tinman.json.XapiContextActivitiesJson.java
License:Open Source License
private JsonArray serialize(ArrayList<XapiActivity> theActivityArray, JsonSerializationContext theSerializationContext) { JsonArray theArray = new JsonArray(); for (XapiActivity activity : theActivityArray) { theArray.add(theSerializationContext.serialize(activity, XapiActivity.class)); }//from www.j a v a2 s .co m if (theArray.size() == 0) { return null; } return theArray; }
From source file:com.claresco.tinman.json.XapiContextJson.java
License:Open Source License
@Override public JsonElement serialize(XapiContext arg0, Type arg1, JsonSerializationContext arg2) { JsonObject result = new JsonObject(); if (arg0.hasInstructor()) { result.add("instructor", arg2.serialize(arg0.getInstructor(), XapiActor.class)); }/* w ww. j a va 2 s .c om*/ if (arg0.hasTeam()) { result.add("team", arg2.serialize(arg0.getTeam(), XapiGroup.class)); } if (arg0.hasRegistration()) { result.addProperty("registration", arg0.getRegistration().toString()); } if (arg0.hasRevision()) { result.addProperty("revision", arg0.getRevision()); } if (arg0.hasPlatform()) { result.addProperty("platform", arg0.getPlatform()); } if (arg0.hasLanguage()) { result.addProperty("language", arg0.getLanguage()); } if (arg0.hasContextActivities()) { result.add("contextActivities", arg2.serialize(arg0.getContextActivities(), XapiContextActivities.class)); } if (arg0.hasStatementReference()) { result.add("statement", arg2.serialize(arg0.getStatementReference(), XapiStatementRef.class)); } return result; }
From source file:com.claresco.tinman.json.XapiCredentialsJson.java
License:Open Source License
@Override public JsonElement serialize(XapiCredentials arg0, Type arg1, JsonSerializationContext arg2) { JsonObject theResult = new JsonObject(); theResult.add(ACTORS, arg2.serialize(arg0.getPerson(), XapiPerson.class)); theResult.add(HISTORICAL, new JsonPrimitive(arg0.getHistorical())); theResult.add(SCOPE, JsonUtility.convertToJsonArray(arg0.getScope())); theResult.addProperty(EXPIRY, arg0.getExpiry().toString()); if (arg0.hasRegistration()) { theResult.addProperty(REGISTRATION, arg0.getRegistration().toString()); }//ww w . j ava 2s. c om if (arg0.hasActivityIDs()) { theResult.add(ACTIVITY, JsonUtility.convertToJsonArrayFromIRIList(arg0.getActivityIDs())); } return theResult; }
From source file:com.claresco.tinman.json.XapiCredentialsListJson.java
License:Open Source License
@Override public JsonElement serialize(XapiCredentialsList arg0, Type arg1, JsonSerializationContext arg2) { JsonArray theResult = new JsonArray(); for (XapiKeySecret theKS : arg0.keySet()) { JsonObject theObject = new JsonObject(); JsonObject theKeySecretJson = new JsonObject(); theKeySecretJson.addProperty(KEY, theKS.getKey()); theKeySecretJson.addProperty(SECRET, theKS.getSecret()); theObject.add(KEYSECRET, theKeySecretJson); theObject.add(CREDENTIALS, arg2.serialize(arg0.get(theKS), XapiCredentials.class)); theResult.add(theObject);/*ww w. j av a 2 s. c o m*/ } return theResult; }
From source file:com.claresco.tinman.json.XapiObjectJson.java
License:Open Source License
@Override public JsonElement serialize(XapiObject arg0, Type arg1, JsonSerializationContext arg2) { JsonObject result = new JsonObject(); if (arg0.getObjectType().equals("Agent")) { result = (JsonObject) arg2.serialize(arg0, XapiAgent.class); } else if (arg0.getObjectType().equals("Group")) { result = (JsonObject) arg2.serialize(arg0, XapiGroup.class); } else if (arg0.getObjectType().equals("Activity")) { result = (JsonObject) arg2.serialize(arg0, XapiActivity.class); } else if (arg0.getObjectType().equals("StatementRef")) { result = (JsonObject) arg2.serialize(arg0, XapiStatementRef.class); } else if (arg0.getObjectType().equals("SubStatement")) { result = (JsonObject) arg2.serialize(arg0, XapiSubStatement.class); }/*ww w. ja v a2s. c o m*/ return result; }
From source file:com.claresco.tinman.json.XapiPersonJson.java
License:Open Source License
@Override public JsonElement serialize(XapiPerson arg0, Type arg1, JsonSerializationContext arg2) { JsonObject theResult = new JsonObject(); theResult.addProperty("objectType", "Person"); if (arg0.hasNames()) { JsonArray theNamesJson = JsonUtility.convertToJsonArray(arg0.getNames()); if (theNamesJson.size() > 0) { theResult.add("name", theNamesJson); }/* w ww .j ava 2s . co m*/ } if (arg0.hasMboxes()) { JsonArray theMboxesJson = JsonUtility.convertToJsonArrayFromIRIList(arg0.getMboxes()); if (theMboxesJson.size() > 0) { theResult.add("mbox", theMboxesJson); } } if (arg0.hasMboxSha1sums()) { JsonArray theMboxSha1sumsJson = JsonUtility.convertToJsonArray(arg0.getMboxSha1sums()); if (theMboxSha1sumsJson.size() > 0) { theResult.add("mbox_sha1sum", theMboxSha1sumsJson); } } if (arg0.hasOpendIDs()) { JsonArray theOpenIDsJson = JsonUtility.convertToJsonArray(arg0.getOpenIDs()); if (theOpenIDsJson.size() > 0) { theResult.add("openid", theOpenIDsJson); } } if (arg0.hasAccounts()) { ArrayList<XapiAccount> theAccounts = arg0.getAccounts(); JsonArray theAccountsJson = new JsonArray(); for (XapiAccount a : theAccounts) { theAccountsJson.add(arg2.serialize(a, XapiAccount.class)); } if (theAccountsJson.size() > 0) { theResult.add("account", theAccountsJson); } } return theResult; }
From source file:com.claresco.tinman.json.XapiResultJson.java
License:Open Source License
@Override public JsonElement serialize(XapiResult arg0, Type arg1, JsonSerializationContext arg2) { JsonObject result = new JsonObject(); if (arg0.hasScore()) { result.add("score", arg2.serialize(arg0.getScore(), XapiScore.class)); }// ww w . ja v a2 s.c om if (arg0.hasSuccess()) { result.addProperty("success", arg0.getSuccess()); } if (arg0.hasCompletion()) { result.addProperty("completion", arg0.getCompletion()); } if (arg0.hasResponse()) { result.addProperty("response", arg0.getResponse()); } if (arg0.hasDuration()) { result.addProperty("duration", arg0.getDuration().toString()); } if (arg0.hasExtension()) { result.add("extensions", arg2.serialize(arg0.getExtension(), XapiExtension.class)); } return result; }