Example usage for com.google.gson JsonObject add

List of usage examples for com.google.gson JsonObject add

Introduction

In this page you can find the example usage for com.google.gson JsonObject add.

Prototype

public void add(String property, JsonElement value) 

Source Link

Document

Adds a member, which is a name-value pair, to self.

Usage

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));
        }/*from   w  w w.j  av a  2  s  .  c om*/
        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.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  va2 s.co m

    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());
    }/*from w  w  w .  ja  v  a 2  s  . c o m*/

    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);//from  ww  w. ja  v  a 2s. c o  m
    }

    return theResult;
}

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());
    }/*w  w  w . jav  a  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;
    }/*  w  w w. ja  va2  s. co  m*/

    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());
    }/*w  w  w  .j av  a2s.  c  o  m*/
    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.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);
        }//from ww  w  . j av  a  2 s  . c  om
    }

    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));
    }/*from  w w w.j  a v a2 s. co  m*/

    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;
}

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()));
    }//from   www. 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;
}