Search in sources :

Example 66 with JsonPrimitive

use of com.google.gson.JsonPrimitive in project play-cookbook by spinscale.

the class SearchHelperPlugin method getJsonStatus.

@Override
public JsonObject getJsonStatus() {
    JsonObject obj = new JsonObject();
    List<ApplicationClass> classes = Play.classes.getAssignableClasses(IndexedModel.class);
    for (ApplicationClass applicationClass : classes) {
        if (isIndexed(applicationClass)) {
            List<String> fieldList = getIndexedFields(applicationClass);
            JsonArray fields = new JsonArray();
            for (String field : fieldList) {
                fields.add(new JsonPrimitive(field));
            }
            obj.add(applicationClass.name, fields);
        }
    }
    return obj;
}
Also used : JsonArray(com.google.gson.JsonArray) JsonPrimitive(com.google.gson.JsonPrimitive) JsonObject(com.google.gson.JsonObject) ApplicationClass(play.classloading.ApplicationClasses.ApplicationClass)

Example 67 with JsonPrimitive

use of com.google.gson.JsonPrimitive in project chuidiang-ejemplos by chuidiang.

the class JsonExample2 method main.

public static void main(String[] args) {
    // to JSON primitive
    JsonPrimitive primitive = new JsonPrimitive(Boolean.TRUE);
    System.out.println(primitive);
    // to json object
    JsonObject object = new JsonObject();
    object.addProperty("name", "Juan");
    object.addProperty("age", 22);
    object.addProperty("birthday", new Date().toString());
    System.out.println(object.toString());
    // to json array
    JsonArray array = new JsonArray();
    array.add(object);
    array.add(object);
    System.out.println(array.toString());
    // Parse from primitive
    JsonParser parser = new JsonParser();
    JsonElement elementPimitive = parser.parse("true");
    if (elementPimitive.isJsonPrimitive() && elementPimitive.getAsJsonPrimitive().isBoolean()) {
        System.out.println(elementPimitive.getAsBoolean());
    }
    JsonElement elementObject = parser.parse("{'name':'Juan','age':22,'birthday':'Wed Feb 26 20:39:53 CET 2014'}");
    System.out.println(elementObject.getAsJsonObject().get("name").getAsString());
    JsonElement arrayElement = parser.parse("[{'name':'Juan','age':22,'birthday':'Wed Feb 26 20:44:23 CET 2014'}," + "{'name':'Juan','age':22,'birthday':'Wed Feb 26 20:39:53 CET 2014'}]");
    System.out.println(arrayElement.getAsJsonArray().size());
    System.out.println(arrayElement.getAsJsonArray().get(0).getAsJsonObject().get("age").getAsInt());
}
Also used : JsonArray(com.google.gson.JsonArray) JsonPrimitive(com.google.gson.JsonPrimitive) JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject) Date(java.util.Date) JsonParser(com.google.gson.JsonParser)

Example 68 with JsonPrimitive

use of com.google.gson.JsonPrimitive in project trex-stateless-gui by cisco-system-traffic-generator.

the class BuilderDataBinding method buildInstruction.

private JsonElement buildInstruction(String instructionId, Map<String, String> parameters) {
    JsonObject instruction = new JsonObject();
    instruction.add("id", new JsonPrimitive(instructionId));
    JsonObject params = new JsonObject();
    parameters.entrySet().stream().forEach(entry -> {
        params.add(entry.getKey(), new JsonPrimitive(entry.getValue()));
    });
    instruction.add("parameters", params);
    return instruction;
}
Also used : JsonPrimitive(com.google.gson.JsonPrimitive) JsonObject(com.google.gson.JsonObject)

Example 69 with JsonPrimitive

use of com.google.gson.JsonPrimitive in project cdap by caskdata.

the class WorkflowActionSpecificationCodec method serialize.

@Override
public JsonElement serialize(WorkflowActionSpecification src, Type typeOfSrc, JsonSerializationContext context) {
    JsonObject jsonObj = new JsonObject();
    jsonObj.add("className", new JsonPrimitive(src.getClassName()));
    jsonObj.add("name", new JsonPrimitive(src.getName()));
    jsonObj.add("description", new JsonPrimitive(src.getDescription()));
    jsonObj.add("datasets", serializeSet(src.getDatasets(), context, String.class));
    jsonObj.add("properties", serializeMap(src.getProperties(), context, String.class));
    return jsonObj;
}
Also used : JsonPrimitive(com.google.gson.JsonPrimitive) JsonObject(com.google.gson.JsonObject)

Example 70 with JsonPrimitive

use of com.google.gson.JsonPrimitive in project cdap by caskdata.

the class CustomActionSpecificationCodec method serialize.

@Override
public JsonElement serialize(CustomActionSpecification src, Type typeOfSrc, JsonSerializationContext context) {
    JsonObject jsonObj = new JsonObject();
    jsonObj.add("className", new JsonPrimitive(src.getClassName()));
    jsonObj.add("name", new JsonPrimitive(src.getName()));
    jsonObj.add("description", new JsonPrimitive(src.getDescription()));
    jsonObj.add("datasets", serializeSet(src.getDatasets(), context, String.class));
    jsonObj.add("properties", serializeMap(src.getProperties(), context, String.class));
    return jsonObj;
}
Also used : JsonPrimitive(com.google.gson.JsonPrimitive) JsonObject(com.google.gson.JsonObject)

Aggregations

JsonPrimitive (com.google.gson.JsonPrimitive)230 JsonObject (com.google.gson.JsonObject)137 JsonArray (com.google.gson.JsonArray)118 JsonElement (com.google.gson.JsonElement)106 Test (org.testng.annotations.Test)56 Test (org.junit.Test)12 Map (java.util.Map)10 Matchers.anyString (org.mockito.Matchers.anyString)8 JsonProcessorInjectionMap (com.builtbroken.mc.lib.json.loading.JsonProcessorInjectionMap)7 Gson (com.google.gson.Gson)6 HashMap (java.util.HashMap)5 GsonBuilder (com.google.gson.GsonBuilder)4 JsonParser (com.google.gson.JsonParser)4 ArrayList (java.util.ArrayList)4 Date (java.util.Date)4 Type (java.lang.reflect.Type)3 HashSet (java.util.HashSet)3 Matcher (java.util.regex.Matcher)3 LobWrapper (angularBeans.io.LobWrapper)2 DatasetCreationSpec (co.cask.cdap.internal.dataset.DatasetCreationSpec)2