本文整理汇总了Java中javax.json.JsonObjectBuilder.addNull方法的典型用法代码示例。如果您正苦于以下问题:Java JsonObjectBuilder.addNull方法的具体用法?Java JsonObjectBuilder.addNull怎么用?Java JsonObjectBuilder.addNull使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.json.JsonObjectBuilder
的用法示例。
在下文中一共展示了JsonObjectBuilder.addNull方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setProperties
import javax.json.JsonObjectBuilder; //导入方法依赖的package包/类
@Override
protected void setProperties() {
final DirectoryNode dirNode = (DirectoryNode)entry;
final JsonObjectBuilder jsonBuilder = Json.createObjectBuilder();
ClassID storageClsid = dirNode.getStorageClsid();
if (storageClsid == null) {
jsonBuilder.addNull("storage_clsid");
} else {
jsonBuilder.add("storage_clsid", storageClsid.toString());
}
dirNode.forEach(e -> {
if (e instanceof DocumentNode) {
DocumentNode dn = (DocumentNode)e;
jsonBuilder.add(escapeString(dn.getName()), "Size: "+dn.getSize());
}
});
final String props = jsonBuilder.build().toString();
if (surrugateEntry != null) {
treeObservable.mergeProperties(props);
} else {
treeObservable.setProperties(props);
}
}
示例2: getProperties
import javax.json.JsonObjectBuilder; //导入方法依赖的package包/类
private String getProperties() {
final JsonObjectBuilder jsonBuilder = Json.createObjectBuilder();
final long id = property.getID();
jsonBuilder.add("ID", id);
jsonBuilder.add("Type", property.getType());
jsonBuilder.add("VariantName", id == 0 ? "dictionary" : Variant.getVariantName(property.getType()));
switch ((int)property.getType()) {
case Variant.VT_CF:
jsonBuilder.add("Value", "<see binary/save entry>");
break;
case Variant.VT_ARRAY | Variant.VT_I2:
case Variant.VT_ARRAY | Variant.VT_I4:
case Variant.VT_ARRAY | Variant.VT_R4:
case Variant.VT_ARRAY | Variant.VT_R8:
case Variant.VT_ARRAY | Variant.VT_CY:
case Variant.VT_ARRAY | Variant.VT_DATE:
case Variant.VT_ARRAY | Variant.VT_BSTR:
case Variant.VT_ARRAY | Variant.VT_ERROR:
case Variant.VT_ARRAY | Variant.VT_BOOL:
case Variant.VT_ARRAY | Variant.VT_VARIANT:
case Variant.VT_ARRAY | Variant.VT_DECIMAL:
case Variant.VT_ARRAY | Variant.VT_I1:
case Variant.VT_ARRAY | Variant.VT_UI1:
case Variant.VT_ARRAY | Variant.VT_UI2:
case Variant.VT_ARRAY | Variant.VT_UI4:
case Variant.VT_ARRAY | Variant.VT_INT:
case Variant.VT_ARRAY | Variant.VT_UINT:
jsonBuilder.add("Value", VariantSpy.arrayToJson(property, propertySet));
break;
case Variant.VT_VECTOR | Variant.VT_I2:
case Variant.VT_VECTOR | Variant.VT_I4:
case Variant.VT_VECTOR | Variant.VT_R4:
case Variant.VT_VECTOR | Variant.VT_R8:
case Variant.VT_VECTOR | Variant.VT_CY:
case Variant.VT_VECTOR | Variant.VT_DATE:
case Variant.VT_VECTOR | Variant.VT_BSTR:
case Variant.VT_VECTOR | Variant.VT_ERROR:
case Variant.VT_VECTOR | Variant.VT_BOOL:
case Variant.VT_VECTOR | Variant.VT_VARIANT:
case Variant.VT_VECTOR | Variant.VT_I1:
case Variant.VT_VECTOR | Variant.VT_UI1:
case Variant.VT_VECTOR | Variant.VT_UI2:
case Variant.VT_VECTOR | Variant.VT_UI4:
case Variant.VT_VECTOR | Variant.VT_I8:
case Variant.VT_VECTOR | Variant.VT_UI8:
case Variant.VT_VECTOR | Variant.VT_LPSTR:
case Variant.VT_VECTOR | Variant.VT_LPWSTR:
case Variant.VT_VECTOR | Variant.VT_FILETIME:
case Variant.VT_VECTOR | Variant.VT_CF:
case Variant.VT_VECTOR | Variant.VT_CLSID:
jsonBuilder.add("Value", VariantSpy.vectorToJson(property, propertySet));
break;
default:
if (property.getValue() == null) {
jsonBuilder.addNull("Value");
} else {
jsonBuilder.add("Value", property.getValue().toString());
}
break;
}
return jsonBuilder.build().toString();
}
示例3: reflectProperties
import javax.json.JsonObjectBuilder; //导入方法依赖的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();
}