Example usage for com.google.gson JsonArray JsonArray

List of usage examples for com.google.gson JsonArray JsonArray

Introduction

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

Prototype

public JsonArray() 

Source Link

Document

Creates an empty JsonArray.

Usage

From source file:com.claresco.tinman.json.JsonUtility.java

License:Open Source License

/**
 * //  ww w .  j ava  2 s .c o m
 * Description:
 *   Create a JsonArray from XapiInteractionComponents
 *
 * Params:
 *
 */
protected static JsonArray jsonArrayFromXapiInteractionComponent(
        ArrayList<XapiInteractionComponent> theComponents, JsonSerializationContext theContext) {
    JsonArray theArray = new JsonArray();

    for (XapiInteractionComponent component : theComponents) {
        theArray.add(theContext.serialize(component));
    }

    return theArray;
}

From source file:com.claresco.tinman.json.JsonUtility.java

License:Open Source License

protected static JsonArray convertToJsonArray(ArrayList<String> theList) {
    JsonArray theArray = new JsonArray();

    for (String s : theList) {
        theArray.add(new JsonPrimitive(s));
    }//from   w w w  .j ava2 s  .c o  m

    return theArray;
}

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.  ja v a 2 s.com

    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.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  . java  2s.  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.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));
    }//w w  w  .  ja  v a 2  s .com
    if (theArray.size() == 0) {
        return null;
    }
    return theArray;
}

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 va2  s .  c om
    }

    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 ww.j av  a2  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.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 w w . j  a v  a  2  s .c o 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.XapiStatementBatchJson.java

License:Open Source License

@Override
public JsonElement serialize(XapiStatementBatch arg0, Type arg1, JsonSerializationContext arg2) {
    JsonArray theStatementArray = new JsonArray();

    if (arg0.size() == 1) {
        JsonElement theStatement = arg2.serialize(arg0.getStatementAtIndex(0), XapiStatement.class);
        theStatementArray.add(theStatement);

        return theStatementArray;
    } else {//from   www  .  j  a v a 2s  .  co m
        for (XapiStatement s : arg0) {
            theStatementArray.add(arg2.serialize(s, XapiStatement.class));
        }
        return theStatementArray;
    }
}

From source file:com.claresco.tinman.servlet.XapiServletUtility.java

License:Open Source License

protected static String createJsonArray(ArrayList<String> theData) {
    JsonArray theArray = new JsonArray();

    for (String s : theData) {
        theArray.add(new JsonPrimitive(s));
    }/*www . ja  v a2 s  . com*/

    return theArray.toString();
}