Example usage for com.google.gson JsonPrimitive JsonPrimitive

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

Introduction

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

Prototype

public JsonPrimitive(Character c) 

Source Link

Document

Create a primitive containing a character.

Usage

From source file:com.code19.library.GsonUtil.java

License:Apache License

public static String objectToJsonDateSerializer(Object ts, final String dateformat) {
    String jsonStr = null;/*from   w w w .j  a v  a 2  s  .c  o m*/
    gson = new GsonBuilder().registerTypeHierarchyAdapter(Date.class, new JsonSerializer<Date>() {
        public JsonElement serialize(Date src, Type typeOfSrc, JsonSerializationContext context) {
            SimpleDateFormat format = new SimpleDateFormat(dateformat);
            return new JsonPrimitive(format.format(src));
        }
    }).setDateFormat(dateformat).create();
    if (gson != null) {
        jsonStr = gson.toJson(ts);
    }
    return jsonStr;
}

From source file:com.codenvy.ide.ext.java.server.TypeBindingConvector.java

License:Open Source License

public static String toJsonBinaryType(SourceTypeBinding binding) {
    JsonObject object = new JsonObject();
    if (!binding.isAnnotationType()) {
        object.add("annotations", toJsonAnnotations(binding.getAnnotations()));
    } else {// w w  w.ja  va 2  s  .  com
        object.add("annotations", JsonNull.INSTANCE);

    }
    object.add("enclosingMethod", null);
    object.add("enclosingTypeName", binding.enclosingType() == null ? JsonNull.INSTANCE
            : new JsonPrimitive(new String(binding.enclosingType().constantPoolName())));

    object.add("fields", toJsonFields(binding.fields()));
    object.add("genericSignature", binding.genericSignature() == null ? JsonNull.INSTANCE
            : new JsonPrimitive(new String(binding.genericSignature())));
    object.add("interfaceNames", toJsonInterfaces(binding.superInterfaces()));
    object.add("memberTypes", toJsonMemberTypes(binding.memberTypes()));
    object.add("methods", toJsonMethods(binding.methods()));
    object.add("missingTypeNames", null);
    object.add("name", binding.constantPoolName() == null ? JsonNull.INSTANCE
            : new JsonPrimitive(new String(binding.constantPoolName())));
    object.add("sourceName", binding.sourceName() == null ? JsonNull.INSTANCE
            : new JsonPrimitive(new String(binding.sourceName())));
    object.add("superclassName", binding.superclass() == null ? JsonNull.INSTANCE
            : new JsonPrimitive(new String(binding.superclass().constantPoolName())));
    long annotationTagBits = binding.getAnnotationTagBits();
    //remove AreMethodsComplete bit tag from type
    annotationTagBits &= ~TagBits.AreMethodsComplete;

    object.add("tagBits", new JsonPrimitive(String.valueOf(annotationTagBits)));
    object.add("anonymous", new JsonPrimitive(binding.isAnonymousType()));
    object.add("local", new JsonPrimitive(binding.isLocalType()));
    object.add("member", new JsonPrimitive(binding.isMemberType()));
    object.add("sourceFileName", binding.sourceName() == null ? JsonNull.INSTANCE
            : new JsonPrimitive(new String(binding.sourceName())));
    object.add("modifiers", new JsonPrimitive(binding.modifiers));
    object.add("binaryType", new JsonPrimitive(true));
    object.add("fileName", null);
    return gson.toJson(object);
}

From source file:com.codenvy.ide.ext.java.server.TypeBindingConvector.java

License:Open Source License

private static JsonElement toJsonMethod(MethodBinding method) {
    JsonObject object = new JsonObject();
    object.addProperty("modifiers", method.getAccessFlags());
    object.addProperty("constructor", method.isConstructor());
    object.add("argumentNames", toJsonParametersName(method.sourceMethod()));
    object.add("annotations", toJsonAnnotations(method.getAnnotations()));
    object.add("defaultValue", toJsonDefaultValue(method.getDefaultValue()));
    object.add("exceptionTypeNames", toJsonExceptionTypeNames(method.thrownExceptions));
    object.add("genericSignature", method.genericSignature() == null ? JsonNull.INSTANCE
            : new JsonPrimitive(new String(method.genericSignature())));
    object.add("methodDescriptor",
            method.signature() == null ? JsonNull.INSTANCE : new JsonPrimitive(new String(method.signature())));
    object.add("parameterAnnotations", toJsonParameterAnnotations(method));
    object.add("selector",
            method.selector == null ? JsonNull.INSTANCE : new JsonPrimitive(new String(method.selector)));
    object.addProperty("tagBits", String.valueOf(method.getAnnotationTagBits()));
    object.addProperty("clinit", false);
    return object;
}

From source file:com.codenvy.ide.ext.java.server.TypeBindingConvector.java

License:Open Source License

private static JsonElement toJsonExceptionTypeNames(ReferenceBinding[] thrownExceptions) {
    if (thrownExceptions == null)
        return JsonNull.INSTANCE;
    JsonArray array = new JsonArray();
    for (ReferenceBinding exception : thrownExceptions) {
        array.add(new JsonPrimitive(new String(exception.constantPoolName())));
    }//www.jav  a  2 s.com
    return array;
}

From source file:com.codenvy.ide.ext.java.server.TypeBindingConvector.java

License:Open Source License

private static JsonElement toJsonParametersName(AbstractMethodDeclaration parameters) {
    if (parameters == null || parameters.arguments == null || parameters.arguments.length == 0)
        return JsonNull.INSTANCE;
    JsonArray array = new JsonArray();

    for (Argument parameter : parameters.arguments) {
        array.add(new JsonPrimitive(new String(parameter.binding.name)));
    }//from  w  w w. j  a  v a2 s. c o m
    return array;

}

From source file:com.codenvy.ide.ext.java.server.TypeBindingConvector.java

License:Open Source License

private static JsonElement toJsonMemberType(ReferenceBinding type) {
    JsonObject object = new JsonObject();
    object.add("enclosingTypeName", type.enclosingType() == null ? JsonNull.INSTANCE
            : new JsonPrimitive(new String(type.enclosingType().constantPoolName())));
    object.addProperty("modifiers", type.modifiers);
    object.add("name", type.constantPoolName() == null ? JsonNull.INSTANCE
            : new JsonPrimitive(new String(type.constantPoolName())));
    return object;
}

From source file:com.codenvy.ide.ext.java.server.TypeBindingConvector.java

License:Open Source License

private static JsonElement toJsonInterfaces(ReferenceBinding[] interfaces) {
    if (interfaces == null)
        return JsonNull.INSTANCE;
    JsonArray array = new JsonArray();
    for (ReferenceBinding anInterface : interfaces) {
        array.add(new JsonPrimitive(new String(anInterface.constantPoolName())));
    }/*from  w ww .  j ava 2s  .  c  o m*/
    return array;
}

From source file:com.codenvy.ide.ext.java.server.TypeBindingConvector.java

License:Open Source License

private static JsonElement toJsonField(FieldBinding field) {
    JsonObject object = new JsonObject();
    object.addProperty("modifiers", field.modifiers);
    object.add("constant", BinaryTypeConvector.toJsonConstant(field.constant()));
    object.add("genericSignature", field.genericSignature() == null ? JsonNull.INSTANCE
            : new JsonPrimitive(new String(field.genericSignature())));
    object.add("name", field.name == null ? JsonNull.INSTANCE : new JsonPrimitive(new String(field.name)));
    object.addProperty("tagBits", String.valueOf(field.tagBits));
    object.add("typeName",
            field.type == null ? JsonNull.INSTANCE : new JsonPrimitive(new String(field.type.signature())));
    object.add("annotations", toJsonAnnotations(field.getAnnotations()));
    return object;
}

From source file:com.codenvy.ide.ext.java.server.TypeBindingConvector.java

License:Open Source License

private static JsonElement toJsonAnnotation(AnnotationBinding annotation) {
    JsonObject object = new JsonObject();
    object.add("typeName", annotation.getAnnotationType() == null ? JsonNull.INSTANCE
            : new JsonPrimitive(new String(annotation.getAnnotationType().constantPoolName())));
    object.add("elementValuePairs", toJsonElementValuePairs(annotation.getElementValuePairs()));
    return object;
}

From source file:com.codenvy.ide.ext.java.server.TypeBindingConvector.java

License:Open Source License

private static JsonElement toJsonElementValuePair(ElementValuePair pair) {
    JsonObject object = new JsonObject();
    object.add("name",
            pair.getName() == null ? JsonNull.INSTANCE : new JsonPrimitive(new String(pair.getName())));
    object.add("value", toJsonDefaultValue(pair.getValue()));
    return object;
}