Java Code Examples for javax.json.JsonArrayBuilder#addNull()
The following examples show how to use
javax.json.JsonArrayBuilder#addNull() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JsonArrays.java From diirt with MIT License | 6 votes |
/** * Converts the given ListNumber to a number JSON array. * * @param list a list of numbers * @return an array of numbers */ public static JsonArrayBuilder fromListNumber(ListNumber list) { JsonArrayBuilder b = Json.createArrayBuilder(); if (list instanceof ListByte || list instanceof ListShort || list instanceof ListInt) { for (int i = 0; i < list.size(); i++) { b.add(list.getInt(i)); } } else if (list instanceof ListLong) { for (int i = 0; i < list.size(); i++) { b.add(list.getLong(i)); } } else { for (int i = 0; i < list.size(); i++) { double value = list.getDouble(i); if (Double.isNaN(value) || Double.isInfinite(value)) { b.addNull(); } else { b.add(value); } } } return b; }
Example 2
Source File: HdfsSerDeImportService.java From hadoop-etl-udfs with MIT License | 5 votes |
private static JsonArrayBuilder getJsonArrayFromFieldData(Object data, ObjectInspector objInsp, JsonBuilderFactory jsonFactory) { JsonArrayBuilder jab = jsonFactory.createArrayBuilder(); ListObjectInspector oi = (ListObjectInspector) objInsp; List<?> list = oi.getList(data); ObjectInspector elemInsp = oi.getListElementObjectInspector(); for (Object obj : list) { if (obj == null) jab.addNull(); else if (elemInsp.getCategory() == Category.PRIMITIVE) { Object o = getJavaObjectFromPrimitiveData(obj, elemInsp); if (o instanceof Integer || o instanceof Short || o instanceof Byte) jab.add((Integer) o); else if (o instanceof Long) jab.add((Long) o); else if (o instanceof Float || o instanceof Double) jab.add((Double) o); else if (o instanceof BigDecimal) jab.add((BigDecimal) o); else if (o instanceof Boolean) jab.add((Boolean) o); else jab.add(o.toString()); } else if (elemInsp.getCategory() == Category.LIST) { jab.add(getJsonArrayFromFieldData(obj, elemInsp, jsonFactory)); } else { jab.add(getJsonObjectFromFieldData(obj, elemInsp, jsonFactory)); } } return jab; }
Example 3
Source File: JsonUtil.java From activemq-artemis with Apache License 2.0 | 5 votes |
public static void addToArray(final Object param, final JsonArrayBuilder jsonArrayBuilder) { if (param instanceof Integer) { jsonArrayBuilder.add((Integer) param); } else if (param instanceof Long) { jsonArrayBuilder.add((Long) param); } else if (param instanceof Double) { jsonArrayBuilder.add((Double) param); } else if (param instanceof String) { jsonArrayBuilder.add((String) param); } else if (param instanceof Boolean) { jsonArrayBuilder.add((Boolean) param); } else if (param instanceof Map) { JsonObject mapObject = toJsonObject((Map<String, Object>) param); jsonArrayBuilder.add(mapObject); } else if (param instanceof Short) { jsonArrayBuilder.add((Short) param); } else if (param instanceof Byte) { jsonArrayBuilder.add(((Byte) param).shortValue()); } else if (param == null) { jsonArrayBuilder.addNull(); } else if (param instanceof byte[]) { JsonArrayBuilder byteArrayObject = toJsonArrayBuilder((byte[]) param); jsonArrayBuilder.add(byteArrayObject); } else { throw ActiveMQClientMessageBundle.BUNDLE.invalidManagementParam(param.getClass().getName()); } }
Example 4
Source File: JsonPartialReader.java From incubator-batchee with Apache License 2.0 | 4 votes |
private void parseArray(final JsonArrayBuilder builder) { while (parser.hasNext()) { final JsonParser.Event next = parser.next(); switch (next) { case VALUE_STRING: builder.add(parser.getString()); break; case VALUE_NUMBER: if (parser.isIntegralNumber()) { builder.add(parser.getLong()); } else { builder.add(parser.getBigDecimal()); } break; case START_OBJECT: JsonObjectBuilder subObject = provider.createObjectBuilder(); parseObject(subObject); builder.add(subObject); break; case START_ARRAY: JsonArrayBuilder subArray = provider.createArrayBuilder(); parseArray(subArray); builder.add(subArray); break; case END_ARRAY: return; case VALUE_NULL: builder.addNull(); break; case VALUE_TRUE: builder.add(true); break; case VALUE_FALSE: builder.add(false); break; case KEY_NAME: throw new JsonParsingException("array doesn't have keys", parser.getLocation()); case END_OBJECT: throw new JsonParsingException("'}', shouldn't occur", parser.getLocation()); default: throw new JsonParsingException(next.name() + ", shouldn't occur", parser.getLocation()); } } }