当前位置: 首页>>代码示例>>Java>>正文


Java JsonArrayBuilder.addNull方法代码示例

本文整理汇总了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();
}
 
开发者ID:SixArmDonkey,项目名称:aerodrome-for-jet,代码行数:41,代码来源:Utils.java

示例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();
    }
}
 
开发者ID:ops4j,项目名称:org.ops4j.ramler,代码行数:16,代码来源:ExampleSpecJsonRenderer.java

示例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;
}
 
开发者ID:EXASOL,项目名称:hadoop-etl-udfs,代码行数:33,代码来源:HdfsSerDeImportService.java

示例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();
}
 
开发者ID:kiwiwings,项目名称:poi-visualizer,代码行数:48,代码来源:TreeModelUtils.java

示例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 ) );
}
 
开发者ID:peter-mount,项目名称:opendata-common,代码行数:6,代码来源:JsonUtils.java


注:本文中的javax.json.JsonArrayBuilder.addNull方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。