Example usage for com.google.gson JsonNull INSTANCE

List of usage examples for com.google.gson JsonNull INSTANCE

Introduction

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

Prototype

JsonNull INSTANCE

To view the source code for com.google.gson JsonNull INSTANCE.

Click Source Link

Document

singleton for JsonNull

Usage

From source file:org.eclipse.che.jdt.BinaryTypeConvector.java

License:Open Source License

private static JsonElement toJsonMissingTypeNames(char[][][] missingTypeNames) {
    if (missingTypeNames == null)
        return JsonNull.INSTANCE;
    JsonArray array = new JsonArray();
    for (char[][] typeName : missingTypeNames) {
        array.add(toJsonArrayString(typeName));
    }/*from   w w  w. j a  va2 s .c om*/
    return array;
}

From source file:org.eclipse.che.jdt.BinaryTypeConvector.java

License:Open Source License

public static JsonElement toJsonArrayString(char[][] chars) {
    if (chars == null)
        return JsonNull.INSTANCE;
    JsonArray array = new JsonArray();
    for (char[] aChar : chars) {
        array.add(new JsonPrimitive(new String(aChar)));
    }/*from  ww w .ja  va  2s. c o m*/
    return array;
}

From source file:org.eclipse.che.jdt.JsonSearchRequester.java

License:Open Source License

@Override
public void acceptConstructor(int modifiers, char[] simpleTypeName, int parameterCount, char[] signature,
        char[][] parameterTypes, char[][] parameterNames, int typeModifiers, char[] packageName, int extraFlags,
        String path, AccessRestriction access) {
    if (access != null) {
        switch (access.getProblemId()) {
        case IProblem.ForbiddenReference:
            return;
        }/*from w ww.  ja  v a 2  s . c o  m*/
    }
    JsonObject constructor = new JsonObject();
    constructor.addProperty("modifiers", modifiers);
    constructor.addProperty("simpleTypeName", new String(simpleTypeName));
    constructor.addProperty("parameterCount", parameterCount);
    constructor.add("signature",
            signature == null ? JsonNull.INSTANCE : new JsonPrimitive(new String(signature)));
    constructor.add("parameterTypes", BinaryTypeConvector.toJsonArrayString(parameterTypes));
    constructor.add("parameterNames", BinaryTypeConvector.toJsonArrayString(parameterNames));
    constructor.addProperty("typeModifiers", typeModifiers);
    constructor.addProperty("packageName", new String(packageName));
    constructor.addProperty("extraFlags", extraFlags);
    result.add(constructor);
}

From source file:org.eclipse.jgit.diff.EditDeserializer.java

License:Apache License

@Override
public JsonElement serialize(final Edit src, final Type typeOfSrc, final JsonSerializationContext context) {
    if (src == null) {
        return JsonNull.INSTANCE;
    }//  w ww  . j a v a  2 s .  c om
    final JsonArray a = new JsonArray();
    add(a, src);
    if (src instanceof ReplaceEdit) {
        for (Edit e : ((ReplaceEdit) src).getInternalEdits()) {
            add(a, e);
        }
    }
    return a;
}

From source file:org.eclipse.milo.opcua.binaryschema.gson.JsonStructureCodec.java

License:Open Source License

@Override
protected JsonElement opcUaToMemberTypeScalar(String name, Object value, String typeName) {
    if (value == null) {
        return JsonNull.INSTANCE;
    } else if (value instanceof Number) {
        if (value instanceof UByte) {
            return new JsonPrimitive(((UByte) value).shortValue());
        } else if (value instanceof UShort) {
            return new JsonPrimitive(((UShort) value).intValue());
        } else if (value instanceof UInteger) {
            return new JsonPrimitive(((UInteger) value).longValue());
        } else if (value instanceof ULong) {
            return new JsonPrimitive(((ULong) value).toBigInteger());
        } else {//  w  w  w .ja v a 2 s. com
            return new JsonPrimitive((Number) value);
        }
    } else if (value instanceof Boolean) {
        return new JsonPrimitive((Boolean) value);
    } else if (value instanceof String) {
        return new JsonPrimitive((String) value);
    } else if (value instanceof Character) {
        return new JsonPrimitive((Character) value);
    } else if (value instanceof JsonElement) {
        return (JsonElement) value;
    } else if (value instanceof DateTime) {
        return new JsonPrimitive(((DateTime) value).getUtcTime());
    } else if (value instanceof UUID) {
        return new JsonPrimitive(value.toString());
    } else if (value instanceof LocalizedText) {
        return gson.toJsonTree(value);
    } else if (value instanceof QualifiedName) {
        return gson.toJsonTree(value);
    } else if (value instanceof ByteString) {
        ByteString byteString = (ByteString) value;
        byte[] bs = byteString.bytesOrEmpty();
        JsonArray array = new JsonArray();
        for (Byte b : bs) {
            array.add(new JsonPrimitive(b));
        }
        return array;
    } else if (value instanceof XmlElement) {
        String fragment = ((XmlElement) value).getFragment();
        return fragment != null ? new JsonPrimitive(fragment) : JsonNull.INSTANCE;
    } else if (value instanceof NodeId) {
        String nodeId = ((NodeId) value).toParseableString();
        return new JsonPrimitive(nodeId);
    } else if (value instanceof ExpandedNodeId) {
        String xNodeId = ((ExpandedNodeId) value).toParseableString();
        return new JsonPrimitive(xNodeId);
    } else if (value instanceof StatusCode) {
        long code = ((StatusCode) value).getValue();
        return new JsonPrimitive(code);
    } else {
        throw new RuntimeException("could not create JsonElement for value: " + value);
    }
}

From source file:org.eclipse.scada.base.json.VariantJsonSerializer.java

License:Open Source License

@Override
public JsonElement serialize(final Variant src, final Type typeOfSrc, final JsonSerializationContext context) {
    if (src == null) {
        return JsonNull.INSTANCE;
    }/*from w  w w .ja v a  2 s  .  co  m*/

    final JsonObject result = new JsonObject();
    result.addProperty(VariantJson.FIELD_TYPE, src.getType().toString());
    switch (src.getType()) {
    case BOOLEAN:
        result.addProperty(VariantJson.FIELD_VALUE, src.asBoolean(null));
        break;
    case DOUBLE: //$FALL-THROUGH$
    case INT32: //$FALL-THROUGH$
    case INT64:
        result.addProperty(VariantJson.FIELD_VALUE, (Number) src.getValue());
        break;
    case STRING:
        result.addProperty(VariantJson.FIELD_VALUE, src.asString(null));
        break;
    case NULL:
        result.add(VariantJson.FIELD_VALUE, JsonNull.INSTANCE);
        break;
    default:
        throw new RuntimeException(String.format("Unknown variant type '%s' encountered", src.getType()));
    }
    return result;
}

From source file:org.eel.kitchen.jsonschema.GsonProvider.java

License:Open Source License

private JsonElement jsonNodeToGson(final JsonNode node) {
    if (node.isNull())
        return JsonNull.INSTANCE;
    if (node.isTextual())
        return new JsonPrimitive(node.textValue());
    if (node.isBoolean())
        return new JsonPrimitive(node.booleanValue());
    if (node.isNumber())
        return new JsonPrimitive(node.numberValue());

    return node.isArray() ? arrayNodeToGson(node) : objectNodeToGson(node);
}

From source file:org.fenixedu.cms.domain.SiteExporter.java

License:Open Source License

protected JsonObject export(Post post) {
    JsonObject json = new JsonObject();
    json.addProperty("slug", post.getSlug());
    json.addProperty("site", post.getSite().getSlug());
    json.add("name", post.getName().json());
    json.add("body", post.getBody().json());
    json.addProperty("createdBy", post.getCreatedBy().getUsername());
    json.add("creationDate", toJson(post.getCreationDate()));
    json.add("canViewGroup", export(post.getCanViewGroup()));
    json.add("categories", toArray(post.getCategoriesSet().stream().map(Category::getSlug)));
    json.addProperty("active", post.getActive());
    json.add("location", ofNullable(post.getLocation()).map(LocalizedString::json).orElse(JsonNull.INSTANCE));
    json.add("metadata", ofNullable(post.getMetadata()).map(PostMetadata::json).orElse(JsonNull.INSTANCE));
    json.add("modificationDate", toJson(post.getModificationDate()));
    json.add("publicationBegin", toJson(post.getPublicationBegin()));
    json.add("publicationEnd", toJson(post.getPublicationEnd()));
    json.add("files", toJsonArray(post.getFilesSet().stream().map(this::export)));
    return json;//from   w w  w.  j  a v  a  2s . co m
}

From source file:org.fenixedu.cms.domain.SiteExporter.java

License:Open Source License

private JsonElement export(Group group) {
    return group != null ? new JsonPrimitive(group.getExpression()) : JsonNull.INSTANCE;
}

From source file:org.fenixedu.cms.domain.SiteExporter.java

License:Open Source License

private JsonElement toJson(DateTime date) {
    return date != null ? new JsonPrimitive(date.toDateTimeISO().toString()) : JsonNull.INSTANCE;
}