本文整理汇总了Java中javax.json.JsonBuilderFactory.createArrayBuilder方法的典型用法代码示例。如果您正苦于以下问题:Java JsonBuilderFactory.createArrayBuilder方法的具体用法?Java JsonBuilderFactory.createArrayBuilder怎么用?Java JsonBuilderFactory.createArrayBuilder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.json.JsonBuilderFactory
的用法示例。
在下文中一共展示了JsonBuilderFactory.createArrayBuilder方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toJSON
import javax.json.JsonBuilderFactory; //导入方法依赖的package包/类
public JsonObject toJSON() {
JsonBuilderFactory f = Json.createBuilderFactory(null);
JsonObjectBuilder json = f.createObjectBuilder();
if (name != null) json.add("name", name);
if (type != null) json.add("script_type", type);
if (loadScript != null) json.add("load_script", loadScript);
if (created != null) json.add("created", DateUtils.toIso8601(created));
if (updated != null) json.add("updated", DateUtils.toIso8601(updated));
if (dataStores != null && !dataStores.isEmpty()) {
JsonArrayBuilder dataStoresJson = f.createArrayBuilder();
for (int d : dataStores) {
dataStoresJson.add(d);
}
json.add("data_stores", dataStoresJson);
}
return json.build();
}
示例2: serialize
import javax.json.JsonBuilderFactory; //导入方法依赖的package包/类
public static JsonObjectBuilder serialize(SchemaMetadata schema) {
JsonBuilderFactory factory = JsonHelper.getBuilderFactory();
JsonObjectBuilder root = factory.createObjectBuilder();
JsonArrayBuilder tablesBuilder = factory.createArrayBuilder();
for (TableMetadata table : schema.getTables()) {
tablesBuilder.add(serializeTableMetadata(table, factory.createObjectBuilder()));
}
root.add("tables", tablesBuilder);
root.add("adapterNotes", schema.getAdapterNotes());
return root;
}
示例3: getJsonArrayFromFieldData
import javax.json.JsonBuilderFactory; //导入方法依赖的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: convert
import javax.json.JsonBuilderFactory; //导入方法依赖的package包/类
public static JsonArray convert(ResultSet rs)
throws SQLException {
JsonBuilderFactory factory = Json.createBuilderFactory(null);
JsonArrayBuilder arrayBuilder = factory.createArrayBuilder();
ResultSetMetaData rsmd = rs.getMetaData();
while (rs.next()) {
int numColumns = rsmd.getColumnCount();
JsonObjectBuilder objBuilder = Json.createObjectBuilder();
for (int i = 1; i < numColumns + 1; i++) {
String column_name = rsmd.getColumnName(i);
if (rsmd.getColumnType(i) == java.sql.Types.BIGINT) {
objBuilder.add(column_name, rs.getInt(column_name));
} else if (rsmd.getColumnType(i) == java.sql.Types.BOOLEAN) {
objBuilder.add(column_name, rs.getBoolean(column_name));
} else if (rsmd.getColumnType(i) == java.sql.Types.DOUBLE) {
objBuilder.add(column_name, rs.getDouble(column_name));
} else if (rsmd.getColumnType(i) == java.sql.Types.FLOAT) {
objBuilder.add(column_name, rs.getFloat(column_name));
} else if (rsmd.getColumnType(i) == java.sql.Types.INTEGER) {
objBuilder.add(column_name, rs.getInt(column_name));
} else if (rsmd.getColumnType(i) == java.sql.Types.NVARCHAR) {
objBuilder.add(column_name, rs.getNString(column_name));
} else if (rsmd.getColumnType(i) == java.sql.Types.VARCHAR) {
objBuilder.add(column_name, rs.getString(column_name));
} else if (rsmd.getColumnType(i) == java.sql.Types.TINYINT) {
objBuilder.add(column_name, rs.getInt(column_name));
} else if (rsmd.getColumnType(i) == java.sql.Types.SMALLINT) {
objBuilder.add(column_name, rs.getInt(column_name));
} else {
objBuilder.add(column_name, rs.getObject(column_name).toString());
}
}
arrayBuilder.add(objBuilder.build());
}
return arrayBuilder.build();
}
示例5: addsItem
import javax.json.JsonBuilderFactory; //导入方法依赖的package包/类
@Test
public void addsItem() {
final JsonProvider provider = JsonProvider.provider();
final JsonBuilderFactory builderFactory = provider
.createBuilderFactory(null);
final JsonArrayBuilder builder = builderFactory.createArrayBuilder();
JsonBuilderUtils.add(builderFactory, builder, null);
JsonBuilderUtils.add(builderFactory, builder, true);
JsonBuilderUtils.add(builderFactory, builder, "string");
JsonBuilderUtils.add(builderFactory, builder, 'c');
JsonBuilderUtils.add(builderFactory, builder, BigInteger.TEN);
JsonBuilderUtils.add(builderFactory, builder,
BigDecimal.valueOf(1111, 2));
JsonBuilderUtils.add(builderFactory, builder, 22f);
JsonBuilderUtils.add(builderFactory, builder, 22d);
JsonBuilderUtils.add(builderFactory, builder, (byte) 33);
JsonBuilderUtils.add(builderFactory, builder, (int) 44);
JsonBuilderUtils.add(builderFactory, builder, (int) 55);
JsonBuilderUtils.add(builderFactory, builder,
Arrays.<Object> asList("a", 0xbc, "d"));
JsonBuilderUtils.add(builderFactory, builder, new Object[] { 1, "2", 3,
false });
JsonBuilderUtils.add(builderFactory, builder,
Collections.singletonMap("foo", "bar"));
// provider.createWriter(System.out).write(builder.build());
}
示例6: testOccasionsForGroup
import javax.json.JsonBuilderFactory; //导入方法依赖的package包/类
/** Test the ability to retrieve a list of occasions for a given group */
@Test
public void testOccasionsForGroup() {
logger.entering(
clazz, name.getMethodName(), "\n\n+ + + + + Entering " + name.getMethodName() + "\n\n");
String groupId = "3333";
/*
* build the json payload for the occasions
*/
JsonBuilderFactory factory = Json.createBuilderFactory(null);
// collect the expected output in this
JsonArrayBuilder resultsBuilder = factory.createArrayBuilder();
// build the json payload for occasion 1
List<Occasion.Contribution> contributions = new ArrayList<>();
contributions.add(new Occasion.Contribution("0001", 20));
Occasion occasion =
new Occasion(
/* ID */ null,
/* date */ "2117-07-31",
/* group ID */ "1111", // different ID than the others in this test so it's omitted
// from the results
/* interval */ "annual",
/* occasion name */ "John Doe's Birthday",
/* organizer ID */ "0001",
/* recipient ID */ "9998",
contributions);
// insert the occasion into the db
collection.insert(occasion.toDbo());
// occasion1 belongs to a different group. omitted from expected results
// build the json payload for occasion 2
contributions = new ArrayList<>();
contributions.add(new Occasion.Contribution("0002", 50));
contributions.add(new Occasion.Contribution("0003", 50));
occasion =
new Occasion(
/* ID */ null,
/* date */ "2117-09-30",
/* group ID */ groupId,
/* interval */ "annual",
/* occasion name */ "Jill Doe's Birthday",
/* organizer ID */ "0002",
/* recipient ID */ "9997",
contributions);
// insert the occasion into the db and add the result to the expected result array
collection.insert(occasion.toDbo());
occasion = new Occasion(collection.findOne(occasion.toDbo()));
resultsBuilder.add(occasion.toJson());
// build the json payload for occasion 3
contributions = new ArrayList<>();
contributions.add(new Occasion.Contribution("9999", 20));
contributions.add(new Occasion.Contribution("8888", 50));
occasion =
new Occasion(
/* ID */ null,
/* date */ "2018-01-31",
/* group ID */ groupId,
/* interval */ "annual",
/* occasion name */ "Jason Doe's Birthday",
/* organizer ID */ "9999",
/* recipient ID */ "9996",
contributions);
// insert the occasion into the db and add the result to the expected result array
collection.insert(occasion.toDbo());
occasion = new Occasion(collection.findOne(occasion.toDbo()));
resultsBuilder.add(occasion.toJson());
testEndpoint("/?groupId=" + groupId, "GET", resultsBuilder.build().toString(), 200);
logger.exiting(
clazz, name.getMethodName(), "\n\n- - - - - Exiting " + name.getMethodName() + "\n\n");
}
示例7: ArrayContext
import javax.json.JsonBuilderFactory; //导入方法依赖的package包/类
/**
* Constructs this context.
* @param valueProvider the transient {@link JsonValue} provider.
* @param factory the factory to be used to build {@link JsonArray}.
*/
ArrayContext(TransientValueProvider valueProvider, JsonBuilderFactory factory) {
this.valueProvider = valueProvider;
this.builder = factory.createArrayBuilder();
this.currentIndex = -1;
}