本文整理汇总了Java中javax.json.JsonBuilderFactory类的典型用法代码示例。如果您正苦于以下问题:Java JsonBuilderFactory类的具体用法?Java JsonBuilderFactory怎么用?Java JsonBuilderFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JsonBuilderFactory类属于javax.json包,在下文中一共展示了JsonBuilderFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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();
}
示例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();
}
示例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;
}
示例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 ());
}
示例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 ());
}
示例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);
}
示例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();
}
示例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();
}
示例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;
}
示例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();
}
示例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();
}
示例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();
}
示例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");
}
示例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;
}
示例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));
}
}