本文整理汇总了Java中javax.json.JsonBuilderFactory类的典型用法代码示例。如果您正苦于以下问题:Java JsonBuilderFactory类的具体用法?Java JsonBuilderFactory怎么用?Java JsonBuilderFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JsonBuilderFactory类属于javax.json包,在下文中一共展示了JsonBuilderFactory类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: buildPostRunResponse
import javax.json.JsonBuilderFactory; //导入依赖的package包/类
Response buildPostRunResponse(OccasionResponse occasionResponse) {
Throwable notificationThrowable = occasionResponse.getNotificationThrowable();
String requestResponse = occasionResponse.getNotificationType();
if (notificationThrowable != null) {
logger.fine("Throwable message: " + notificationThrowable.getMessage());
}
JsonBuilderFactory factory = Json.createBuilderFactory(null);
JsonObjectBuilder builder = factory.createObjectBuilder();
JsonObject responseBody = null;
if (requestResponse.equals(OccasionResponse.NOTIFICATION_TYPE_LOG)
|| requestResponse.equals(OccasionResponse.NOTIFICATION_TYPE_TWEET)) {
responseBody = builder.add(JSON_KEY_OCCASION_POST_RUN_SUCCESS, requestResponse).build();
} else {
responseBody = builder.add(JSON_KEY_OCCASION_POST_RUN_ERROR, requestResponse).build();
}
return Response.ok(responseBody, MediaType.APPLICATION_JSON).build();
}
开发者ID:OpenLiberty,项目名称:sample-acmegifts,代码行数:19,代码来源:OccasionResource.java
示例2: serialize
import javax.json.JsonBuilderFactory; //导入依赖的package包/类
public static String serialize(SchemaAdapterNotes notes) {
JsonBuilderFactory factory = JsonHelper.getBuilderFactory();
JsonObjectBuilder builder = factory.createObjectBuilder()
.add("catalogSeparator", notes.getCatalogSeparator())
.add("identifierQuoteString", notes.getIdentifierQuoteString())
.add("storesLowerCaseIdentifiers", notes.isStoresLowerCaseIdentifiers())
.add("storesUpperCaseIdentifiers", notes.isStoresUpperCaseIdentifiers())
.add("storesMixedCaseIdentifiers", notes.isStoresMixedCaseIdentifiers())
.add("supportsMixedCaseIdentifiers", notes.isSupportsMixedCaseIdentifiers())
.add("storesLowerCaseQuotedIdentifiers", notes.isStoresLowerCaseQuotedIdentifiers())
.add("storesUpperCaseQuotedIdentifiers", notes.isStoresUpperCaseQuotedIdentifiers())
.add("storesMixedCaseQuotedIdentifiers", notes.isStoresMixedCaseQuotedIdentifiers())
.add("supportsMixedCaseQuotedIdentifiers", notes.isSupportsMixedCaseQuotedIdentifiers())
.add("nullsAreSortedAtEnd", notes.isNullsAreSortedAtEnd())
.add("nullsAreSortedAtStart", notes.isNullsAreSortedAtStart())
.add("nullsAreSortedHigh", notes.isNullsAreSortedHigh())
.add("nullsAreSortedLow", notes.isNullsAreSortedLow());
return builder.build().toString();
}
开发者ID:EXASOL,项目名称:virtual-schemas,代码行数:20,代码来源:SchemaAdapterNotes.java
示例3: makeNotificationConnection
import javax.json.JsonBuilderFactory; //导入依赖的package包/类
@Retry(maxRetries = 2)
@Fallback(NotificationFallbackHandler.class)
public OccasionResponse makeNotificationConnection(
String message,
Orchestrator orchestrator,
String jwtTokenString,
String notification11ServiceUrl,
String twitterHandle,
String notificationServiceUrl)
throws IOException {
JsonBuilderFactory factory = Json.createBuilderFactory(null);
JsonObjectBuilder builder = factory.createObjectBuilder();
JsonObject notificationRequestPayload = builder.add(JSON_KEY_NOTIFICATION, message).build();
Response notificationResponse =
orchestrator.makeConnection(
"POST", notificationServiceUrl, notificationRequestPayload.toString(), jwtTokenString);
OccasionResponse occasionResponse =
new OccasionResponse(notificationResponse, OccasionResponse.NOTIFICATION_TYPE_LOG, null);
return occasionResponse;
}
开发者ID:OpenLiberty,项目名称:sample-acmegifts,代码行数:23,代码来源:NotificationRetryBean.java
示例4: testObject
import javax.json.JsonBuilderFactory; //导入依赖的package包/类
@Test
public void testObject ()
{
HashMap<String, Object> config = new HashMap<String, Object> ();
CookJsonProvider provider = new CookJsonProvider ();
JsonBuilderFactory f = provider.createBuilderFactory (config);
JsonObject model = f.createObjectBuilder ()
.add ("object", f.createObjectBuilder ())
.add ("array", f.createArrayBuilder ())
.add ("double", 1234.5)
.add ("number", new CookJsonInt (1234))
.build ();
StringWriter sw = new StringWriter ();
JsonWriter writer = provider.createWriter (sw);
writer.write (model);
writer.close ();
Assert.assertEquals ("{\"object\":{},\"array\":[],\"double\":1234.5,\"number\":1234}".length (), sw.toString ().length ());
}
开发者ID:coconut2015,项目名称:cookjson,代码行数:22,代码来源:BuilderTest.java
示例5: testArray
import javax.json.JsonBuilderFactory; //导入依赖的package包/类
@Test
public void testArray ()
{
HashMap<String, Object> config = new HashMap<String, Object> ();
CookJsonProvider provider = new CookJsonProvider ();
JsonBuilderFactory f = provider.createBuilderFactory (config);
JsonArray model = f.createArrayBuilder ()
.add (12345678901234L)
.add (1234.5)
.add ("quick brown fox")
.add (new BigInteger ("123456789012345678901234567890"))
.add (f.createArrayBuilder ())
.build ();
StringWriter sw = new StringWriter ();
JsonWriter writer = provider.createWriter (sw);
writer.write (model);
writer.close ();
Assert.assertEquals ("[12345678901234,1234.5,\"quick brown fox\",123456789012345678901234567890,[]]", sw.toString ());
}
开发者ID:coconut2015,项目名称:cookjson,代码行数:23,代码来源:BuilderTest.java
示例6: main
import javax.json.JsonBuilderFactory; //导入依赖的package包/类
public static void main(String[] args) {
JsonBuilderFactory factory = Json.createBuilderFactory(null);
JsonObject jsonObj = factory.createObjectBuilder()
.add("firstName", "John")
.add("lastName", "Doe")
.add("age", 25)
.add("address", factory.createObjectBuilder()
.add("street", "1 Main St.")
.add("city", "New Britain")
.add("state", "CT")
.add("zipCode", "06050"))
.add("phoneNumber", factory.createArrayBuilder()
.add(factory.createObjectBuilder()
.add("type", "home")
.add("number", "860 867-5309"))
.add(factory.createObjectBuilder()
.add("type", "fax")
.add("number", "860 123-4567")))
.build();
System.out.println(jsonObj);
}
开发者ID:CCSU-CS416F16,项目名称:CS416F16CourseInfo,代码行数:22,代码来源:JsonDemo.java
示例7: 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();
}
开发者ID:loadimpact,项目名称:loadimpact-sdk-java,代码行数:18,代码来源:UserScenario.java
示例8: serialize
import javax.json.JsonBuilderFactory; //导入依赖的package包/类
public static String serialize(ColumnAdapterNotes notes) {
JsonBuilderFactory factory = JsonHelper.getBuilderFactory();
JsonObjectBuilder builder = factory.createObjectBuilder()
.add("jdbcDataType", notes.getJdbcDataType())
.add("typeName", notes.getTypeName());
return builder.build().toString();
}
开发者ID:EXASOL,项目名称:virtual-schemas,代码行数:8,代码来源:ColumnAdapterNotes.java
示例9: 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;
}
开发者ID:EXASOL,项目名称:virtual-schemas,代码行数:12,代码来源:SchemaMetadataSerializer.java
示例10: makeDropVirtualSchemaResponse
import javax.json.JsonBuilderFactory; //导入依赖的package包/类
public static String makeDropVirtualSchemaResponse() {
JsonBuilderFactory factory = JsonHelper.getBuilderFactory();
JsonObject res = factory.createObjectBuilder()
.add("type", "dropVirtualSchema")
.build();
return res.toString();
}
开发者ID:EXASOL,项目名称:virtual-schemas,代码行数:8,代码来源:ResponseJsonSerializer.java
示例11: makePushdownResponse
import javax.json.JsonBuilderFactory; //导入依赖的package包/类
public static String makePushdownResponse(String pushdownSql) {
JsonBuilderFactory factory = JsonHelper.getBuilderFactory();
JsonObject res = factory.createObjectBuilder()
.add("type", "pushdown")
.add("sql", pushdownSql)
.build();
return res.toString();
}
开发者ID:EXASOL,项目名称:virtual-schemas,代码行数:9,代码来源:ResponseJsonSerializer.java
示例12: getRequestBodyCreate
import javax.json.JsonBuilderFactory; //导入依赖的package包/类
/**
* @return a string representation of the request body for the create action
*/
String getRequestBodyCreate() {
JsonBuilderFactory factory = Json.createBuilderFactory(null);
JsonObjectBuilder job = factory.createObjectBuilder();
if(!this.destroy) {
job.add("destroy", "false");
}
if(this.chunk > 1) {
job.add("chunk", this.chunk);
}
job.add("format", this.format);
if(this.srctext != null) {
job.add("srctext", this.srctext);
}
if(this.srcurl != null) {
job.add("srcurl", this.srcurl.toString());
}
// test protocol
// job.add("ask", "member((X,Y), [(a(taco),3),(b,4),(c,5)])");
// job.add("template", "X");
// this will be a json object with fields for options
// sample, as a prolog dict
//_{ src_text:"\n q(X) :- p(X).\n p(a). p(b). p(c).\n "}
return job.build().toString();
}
开发者ID:Anniepoo,项目名称:JavaPengine,代码行数:32,代码来源:PengineBuilder.java
示例13: deserialize
import javax.json.JsonBuilderFactory; //导入依赖的package包/类
@Override
protected JsonString deserialize(String jsonValue, Unmarshaller unmarshaller, Type rtType) {
final JsonBuilderFactory factory = unmarshaller.getJsonbContext().getJsonProvider().createBuilderFactory(null);
final JsonObject jsonObject = factory.createObjectBuilder()
.add("json", jsonValue)
.build();
return jsonObject.getJsonString("json");
}
开发者ID:eclipse,项目名称:yasson,代码行数:9,代码来源:JsonStringTypeDeserializer.java
示例14: 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;
}
开发者ID:EXASOL,项目名称:hadoop-etl-udfs,代码行数:33,代码来源:HdfsSerDeImportService.java
示例15: addJsonObjectPair
import javax.json.JsonBuilderFactory; //导入依赖的package包/类
private static void addJsonObjectPair(JsonObjectBuilder job, String key, Object obj, ObjectInspector objInsp, JsonBuilderFactory jsonFactory) {
if (obj == null)
job.addNull(key);
else if (objInsp.getCategory() == Category.PRIMITIVE) {
Object o = getJavaObjectFromFieldData(obj, objInsp);
if (o instanceof Integer)
job.add(key, (Integer) o);
else if (o instanceof Byte)
job.add(key, (Byte) o);
else if (o instanceof Short)
job.add(key, (Short) o);
else if (o instanceof Long)
job.add(key, (Long) o);
else if (o instanceof Float)
job.add(key, (Float) o);
else if (o instanceof Double)
job.add(key, (Double) o);
else if (o instanceof BigDecimal)
job.add(key, (BigDecimal) o);
else if (o instanceof Boolean)
job.add(key, (Boolean) o);
else
job.add(key, o.toString());
}
else if (objInsp.getCategory() == Category.LIST) {
job.add(key, getJsonArrayFromFieldData(obj, objInsp, jsonFactory));
}
else {
job.add(key, getJsonObjectFromFieldData(obj, objInsp, jsonFactory));
}
}
开发者ID:EXASOL,项目名称:hadoop-etl-udfs,代码行数:32,代码来源:HdfsSerDeImportService.java
示例16: serialize
import javax.json.JsonBuilderFactory; //导入依赖的package包/类
public static String serialize(ColumnAdapterNotes notes) {
JsonBuilderFactory factory = JsonHelper.getBuilderFactory();
JsonObjectBuilder builder = factory.createObjectBuilder()
.add("originalTypeName", notes.getOriginalTypeName())
.add("partitionedColumn", notes.isPartitionedColumn());
return builder.build().toString();
}
开发者ID:EXASOL,项目名称:hadoop-etl-udfs,代码行数:8,代码来源:ColumnAdapterNotes.java
示例17: 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();
}
开发者ID:CCSU-CS416F16,项目名称:CS416F16CourseInfo,代码行数:39,代码来源:JsonResultSetConverter.java
示例18: main
import javax.json.JsonBuilderFactory; //导入依赖的package包/类
public static void main(String[] args) {
JsonBuilderFactory factory = Json.createBuilderFactory(null);
JsonArray jsonObj = factory.createArrayBuilder()
.add(factory.createObjectBuilder()
.add("artist", "Green Day")
.add("title", "Dookie")
.add("year", 1994)
.add("musician", factory.createArrayBuilder()
.add(factory.createObjectBuilder()
.add("first", "Billy Joe")
.add("last", "Armstrong"))
.add(factory.createObjectBuilder()
.add("first", "Tre")
.add("last", "Cool"))
)
)
.add(factory.createObjectBuilder()
.add("artist", "Pear Jam")
.add("title", "Ten")
.add("year", 1991)
.add("musician", factory.createArrayBuilder()
.add(factory.createObjectBuilder()
.add("first", "Eddie")
.add("last", "Vedder"))
.add(factory.createObjectBuilder()
.add("first", "Mike")
.add("last", "McCready"))
)
)
.build();
System.out.println(jsonObj);
}
开发者ID:CCSU-CS416F16,项目名称:CS416F16CourseInfo,代码行数:33,代码来源:JsonCDDemo.java
示例19: buildPayload
import javax.json.JsonBuilderFactory; //导入依赖的package包/类
public static JsonObject buildPayload(MessageType messageType, String request, int serverId, int nodeIndex){
Map<String, Object> config = new HashMap<String, Object>();
//if you need pretty printing
config.put("javax.json.stream.JsonGenerator.prettyPrinting", Boolean.valueOf(true));
JsonBuilderFactory factory = Json.createBuilderFactory(config);
JsonObject payload = factory.createObjectBuilder()
.add("MessageType", messageType.toString())
.add("Request", request)
.add("ServerID", serverId)
.add("SendingID", nodeIndex)
.build();
return payload;
}
开发者ID:bethrichardson,项目名称:dynamic-weighted-byzantine-agreement,代码行数:15,代码来源:MsgHandler.java
示例20: testCreateBuilderFactory
import javax.json.JsonBuilderFactory; //导入依赖的package包/类
@Test
public void testCreateBuilderFactory() {
JsonBuilderFactory factory = Json.createBuilderFactory(Collections.emptyMap());
JsonObject jsonObject = factory.createObjectBuilder().
add("name", "home").
add("city", "Vienna")
.build();
//JsonObject
Assert.assertEquals("home", jsonObject.getString("name"));
Assert.assertEquals("Vienna", jsonObject.getString("city"));
}
开发者ID:apache,项目名称:johnzon,代码行数:14,代码来源:JsonBuilderFactoryTest.java
注:本文中的javax.json.JsonBuilderFactory类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论