本文整理匯總了Java中javax.json.JsonArrayBuilder.addNull方法的典型用法代碼示例。如果您正苦於以下問題:Java JsonArrayBuilder.addNull方法的具體用法?Java JsonArrayBuilder.addNull怎麽用?Java JsonArrayBuilder.addNull使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.json.JsonArrayBuilder
的用法示例。
在下文中一共展示了JsonArrayBuilder.addNull方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: toJsonArray
import javax.json.JsonArrayBuilder; //導入方法依賴的package包/類
/**
* Turn some list of Jsonable into a json array
* @param <T>
* @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();
}
示例2: addScalarOrNull
import javax.json.JsonArrayBuilder; //導入方法依賴的package包/類
private void addScalarOrNull(JsonArrayBuilder builder, TypeInstance instance) {
Object value = instance.value();
if (value instanceof Integer) {
builder.add((Integer) value);
}
else if (value instanceof String) {
builder.add((String) value);
}
else if (value instanceof Boolean) {
builder.add((Boolean) value);
}
else if (value == null) {
builder.addNull();
}
}
示例3: getJsonArrayFromFieldData
import javax.json.JsonArrayBuilder; //導入方法依賴的package包/類
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;
}
示例4: reflectProperties
import javax.json.JsonArrayBuilder; //導入方法依賴的package包/類
public static String reflectProperties(Object obj) {
final JsonObjectBuilder jsonBuilder = Json.createObjectBuilder();
for (Method m : getGetter(new ArrayList<>(), obj.getClass())) {
if (useReturnType(m)) {
Matcher match = getter.matcher(m.getName());
match.matches();
final String propName = match.group(1);
Object retVal;
try {
m.setAccessible(true);
retVal = m.invoke(obj);
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
retVal = e.getMessage();
}
if (retVal == null) {
jsonBuilder.addNull(propName);
} else if (retVal instanceof Collection<?>) {
final JsonArrayBuilder arrBuilder = Json.createArrayBuilder();
for (Object o : ((Collection<?>)retVal)) {
if (o == null) {
arrBuilder.addNull();
} else {
arrBuilder.add(o.toString());
}
}
jsonBuilder.add(propName, arrBuilder.build());
} else if (retVal instanceof Double) {
jsonBuilder.add(propName, ((Double)retVal).doubleValue());
} else if (retVal instanceof Boolean) {
jsonBuilder.add(propName, ((Boolean)retVal).booleanValue());
} else if (retVal instanceof Integer || retVal instanceof Short || retVal instanceof Byte) {
jsonBuilder.add(propName, ((Number)retVal).intValue());
} else if (retVal instanceof Long) {
jsonBuilder.add(propName, ((Long)retVal).longValue());
} else if (retVal instanceof BigDecimal) {
jsonBuilder.add(propName, (BigDecimal)retVal);
} else if (retVal instanceof BigInteger) {
jsonBuilder.add(propName, (BigInteger)retVal);
} else {
jsonBuilder.add(propName, retVal.toString());
}
}
}
return jsonBuilder.build().toString();
}
示例5: add
import javax.json.JsonArrayBuilder; //導入方法依賴的package包/類
public static <T> JsonArrayBuilder add( JsonArrayBuilder b, T v, Function<T, Object> f )
{
Objects.requireNonNull( b );
return v == null ? b.addNull() : add( b, f.apply( v ) );
}