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;
}
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());
}
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;
}
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;
}
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;
}
Aggregations