Example usage for javax.json JsonArrayBuilder addNull

List of usage examples for javax.json JsonArrayBuilder addNull

Introduction

In this page you can find the example usage for javax.json JsonArrayBuilder addNull.

Prototype

JsonArrayBuilder addNull();

Source Link

Document

Adds a JsonValue#NULL value to the array.

Usage

From source file:com.buffalokiwi.aerodrome.jet.Utils.java

/**
 * Turn some list of Jsonable into a json array 
 * @param <T>/*  w  ww .  ja  va  2 s  .  c  o  m*/
 * @param data list
 * @return json array 
 */
public static <T extends Object> JsonArray toJsonArray(List<T> data) {
    final JsonArrayBuilder out = Json.createArrayBuilder();

    for (final Object obj : data) {
        if (obj == null)
            out.addNull();
        else if (obj instanceof Jsonable)
            out.add(((Jsonable) obj).toJSON());
        else if (obj instanceof JsonValue)
            out.add((JsonValue) obj);
        else if (obj instanceof BigDecimal)
            out.add((BigDecimal) obj);
        else if (obj instanceof BigInteger)
            out.add((BigInteger) obj);
        else if (obj instanceof Integer)
            out.add((Integer) obj);
        else if (obj instanceof Long)
            out.add((Long) obj);
        else if (obj instanceof Double)
            out.add((Double) obj);
        else if (obj instanceof Boolean)
            out.add((Boolean) obj);
        else if (obj instanceof JsonObjectBuilder)
            out.add((JsonObjectBuilder) obj);
        else if (obj instanceof JsonArrayBuilder)
            out.add((JsonArrayBuilder) obj);
        else
            out.add(obj.toString());
    }

    return out.build();
}