Java 类javax.json.JsonBuilderFactory 实例源码

项目:sample-acmegifts    文件:OccasionResource.java   
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();
  }
项目:sample-acmegifts    文件:NotificationRetryBean.java   
@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;
}
项目:virtual-schemas    文件:SchemaAdapterNotes.java   
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();
}
项目:cookjson    文件:BuilderTest.java   
@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 ());
}
项目:cookjson    文件:BuilderTest.java   
@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 ());
}
项目:CS416F16CourseInfo    文件:JsonDemo.java   
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);
}
项目:loadimpact-sdk-java    文件:UserScenario.java   
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();
}
项目:virtual-schemas    文件:ColumnAdapterNotes.java   
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();
}
项目:virtual-schemas    文件:SchemaMetadataSerializer.java   
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;
}
项目:virtual-schemas    文件:ResponseJsonSerializer.java   
public static String makeDropVirtualSchemaResponse() {
    JsonBuilderFactory factory = JsonHelper.getBuilderFactory();
    JsonObject res = factory.createObjectBuilder()
            .add("type", "dropVirtualSchema")
            .build();
    return res.toString();
}
项目:virtual-schemas    文件:ResponseJsonSerializer.java   
public static String makePushdownResponse(String pushdownSql) {
    JsonBuilderFactory factory = JsonHelper.getBuilderFactory();
    JsonObject res = factory.createObjectBuilder()
            .add("type", "pushdown")
            .add("sql", pushdownSql)
            .build();
    return res.toString();
}
项目:JavaPengine    文件:PengineBuilder.java   
/**
 * @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();
}
项目:yasson    文件:JsonStringTypeDeserializer.java   
@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");
}
项目:hadoop-etl-udfs    文件:HdfsSerDeImportService.java   
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;
}
项目:hadoop-etl-udfs    文件:HdfsSerDeImportService.java   
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));
    }
}
项目:hadoop-etl-udfs    文件:ColumnAdapterNotes.java   
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();
}
项目:CS416F16CourseInfo    文件:JsonResultSetConverter.java   
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();
}
项目:CS416F16CourseInfo    文件:JsonCDDemo.java   
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);
}
项目:dynamic-weighted-byzantine-agreement    文件:MsgHandler.java   
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;
}
项目:johnzon    文件:JsonBuilderFactoryTest.java   
@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"));

}
项目:johnzon    文件:DefaultMappingTest.java   
public static void toJsonStructures() {

        JsonBuilderFactory factory = Json.createBuilderFactory(Collections.emptyMap());
        JsonObject jsonObject = factory.createObjectBuilder().
            add("name", "home").
            add("city", "Prague")
            .build();

        //JsonObject
        assertEquals("{\"name\":\"home\",\"city\":\"Prague\"}", JSONB.toJson(jsonObject));

        JsonArray jsonArray = factory.createArrayBuilder().add(jsonObject).add(jsonObject).build();

        //JsonArray
        assertEquals("[{\"name\":\"home\",\"city\":\"Prague\"},{\"name\":\"home\",\"city\":\"Prague\"}]", JSONB.toJson(jsonArray));

        //JsonStructure
        assertEquals("[{\"name\":\"home\",\"city\":\"Prague\"},{\"name\":\"home\",\"city\":\"Prague\"}]", JSONB.toJson((JsonStructure) jsonArray));

        //JsonValue
        assertEquals("true", JSONB.toJson(JsonValue.TRUE));

        //Map
        Map<String, Object> commonMap = new LinkedHashMap<>();
        commonMap.put("first", 1);
        commonMap.put("second", 2);

        assertEquals("{\"first\":1,\"second\":2}", JSONB.toJson(commonMap));

        //Collection
        Collection<Object> commonList = new ArrayList<>();
        commonList.add(1);
        commonList.add(2);

        assertEquals("[1,2]", JSONB.toJson(commonList));
    }
项目:adapters    文件:Topology.java   
@Override
public JsonObject parseToJson() {

    if (LOGGER.isLoggable(Level.INFO)) {
        LOGGER.log(Level.INFO, "parseToJson : " + this.getInstanceUri());
    }

    JsonBuilderFactory factory = Json.createBuilderFactory(null);
    JsonArrayBuilder serviceContainerBuilder = Json.createArrayBuilder();

    if (LOGGER.isLoggable(Level.INFO)) {
        LOGGER.log(Level.INFO,
                "parseToJson number of service containers : "
                        + this.getServiceContainers().size());
    }

    for (ServiceContainer sc : this.getServiceContainers()) {
        JsonObject json = sc.parseToJson();
        serviceContainerBuilder.add(json);
    }

    String name = null;
    if (this.getOscoName() != null) {
        name = this.getOscoName();
    } else {
        name = this.getInstanceUri();
    }

    JsonArrayBuilder locationsBuilder = Json.createArrayBuilder();
    for (String location : this.getLocations()) {
        locationsBuilder.add(location);
    }

    JsonObject topologyBuilder = factory.createObjectBuilder()
            .add("name", name).add("locations", locationsBuilder)
            .add("serviceContainers", serviceContainerBuilder).build();

    return topologyBuilder;
}
项目:jsonix-schema-compiler    文件:JsonSchemaModuleCompiler.java   
public JsonSchemaModuleCompiler(JsonBuilderFactory jsonBuilderFactory, Modules<T, C> modules, Module<T, C> module,
        JsonSchema jsonSchema) {
    Validate.notNull(jsonBuilderFactory);
    Validate.notNull(module);
    Validate.notNull(jsonSchema);
    this.jsonBuilderFactory = jsonBuilderFactory;
    this.modules = modules;
    this.module = module;
}
项目:jsonix-schema-compiler    文件:JsonSchemaModulesGenerator.java   
public void generate(JsonStructureWriter<T, C> writer) {
    final JsonProvider provider = JsonProvider.provider();
    final JsonBuilderFactory builderFactory = provider.createBuilderFactory(null);
    for (final Module<T, C> module : this.modules.getModules()) {
        if (!module.isEmpty()) {
            for (JsonSchema jsonSchema : module.getJsonSchemas()) {
                final JsonSchemaModuleCompiler<T, C> moduleCompiler = new JsonSchemaModuleCompiler<T, C>(
                        builderFactory, modules, module, jsonSchema);
                final JsonSchemaBuilder moduleSchema = moduleCompiler.compile();
                final JsonObject moduleSchemaJsonObject = moduleSchema.build(builderFactory);
                writer.writeJsonStructure(module, moduleSchemaJsonObject, jsonSchema.getFileName());
            }
        }
    }
}
项目:jsonix-schema-compiler    文件:JsonSchemaMappingCompiler.java   
public JsonSchemaMappingCompiler(JsonBuilderFactory jsonBuilderFactory, Modules<T, C> modules, Module<T, C> module,
        Mapping<T, C> mapping) {
    Validate.notNull(jsonBuilderFactory);
    Validate.notNull(modules);
    Validate.notNull(module);
    Validate.notNull(mapping);
    this.jsonBuilderFactory = jsonBuilderFactory;
    this.modules = modules;
    this.module = module;
    this.mapping = mapping;
}
项目:jsonix-schema-compiler    文件:JsonBuilderUtilsTest.java   
@Test
public void addsProperty() {
    final JsonProvider provider = JsonProvider.provider();
    final JsonBuilderFactory builderFactory = provider
            .createBuilderFactory(null);
    final JsonObjectBuilder builder = builderFactory.createObjectBuilder();
    JsonBuilderUtils.add(builderFactory, builder, "null", null);
    JsonBuilderUtils.add(builderFactory, builder, "true", true);
    JsonBuilderUtils.add(builderFactory, builder, "string", "string");
    JsonBuilderUtils.add(builderFactory, builder, "char", 'c');
    JsonBuilderUtils.add(builderFactory, builder, "bigInteger",
            BigInteger.TEN);
    JsonBuilderUtils.add(builderFactory, builder, "bigDecimal",
            BigDecimal.valueOf(1111, 2));
    JsonBuilderUtils.add(builderFactory, builder, "float", 22f);
    JsonBuilderUtils.add(builderFactory, builder, "double", 22d);
    JsonBuilderUtils.add(builderFactory, builder, "byte", (byte) 33);
    JsonBuilderUtils.add(builderFactory, builder, "int", (int) 44);
    JsonBuilderUtils.add(builderFactory, builder, "short", (int) 55);
    JsonBuilderUtils.add(builderFactory, builder, "list",
            Arrays.<Object> asList("a", 0xbc, "d"));
    JsonBuilderUtils.add(builderFactory, builder, "array", new Object[] {
            1, "2", 3, false });

    JsonBuilderUtils.add(builderFactory, builder, "map",
            Collections.singletonMap("foo", "bar"));
    // provider.createWriter(System.out).write(builder.build());
}
项目:jsonix-schema-compiler    文件:JsonBuilderUtilsTest.java   
@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());
}
项目:sample-acmegifts    文件:OccasionResourceTest.java   
/** 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");
}
项目:hibiscus    文件:ArrayContext.java   
/**
 * 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;
}
项目:virtual-schemas    文件:JsonHelper.java   
public static JsonBuilderFactory getBuilderFactory() {
    Map<String, Object> config = new HashMap<String, Object>();
    return Json.createBuilderFactory(config);
}
项目:CS416F16CourseInfo    文件:AjaxJsonCDDemoServlet.java   
/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("application/xml;charset=UTF-8");
    PrintWriter out = response.getWriter();
    try {
        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();
        out.println(jsonObj.toString());

        // Not required, for lecture purposes only
        request.getServletContext().log(jsonObj.toString());
    } catch (Exception e) {
        request.getServletContext().log(e.getMessage());
    } finally {
        out.close();
    }
}
项目:polygene-java    文件:JavaxJsonFactories.java   
@Override
public JsonBuilderFactory builderFactory()
{
    return builderFactory;
}
项目:activemq-artemis    文件:JsonLoader.java   
public static JsonBuilderFactory createBuilderFactory(Map<String, ?> config) {
   return provider.createBuilderFactory(config);
}
项目:johnzon    文件:JsonProviderImpl.java   
@Override
public JsonBuilderFactory createBuilderFactory(final Map<String, ?> stringMap) {
    return DELEGATE.createBuilderFactory(stringMap);
}
项目:johnzon    文件:JsonProviderImpl.java   
@Override
public JsonBuilderFactory createBuilderFactory(final Map<String, ?> config) {
    return (config == null || config.isEmpty()) ? builderFactory : new JsonBuilderFactoryImpl(config);
}
项目:jsonix-schema-compiler    文件:JsonSchemaModuleCompiler.java   
public JsonBuilderFactory getJsonBuilderFactory() {
    return jsonBuilderFactory;
}
项目:jsonix-schema-compiler    文件:JsonSchemaMappingCompiler.java   
public JsonBuilderFactory getJsonBuilderFactory() {
    return jsonBuilderFactory;
}
项目:jsonix-schema-compiler    文件:JsonObjectBuildable.java   
public JsonObjectBuilder build(JsonBuilderFactory builderFactory,
JsonObjectBuilder builder);
项目:jsonix-schema-compiler    文件:JsonSchemaBuilder.java   
@Override
public JsonObject build(JsonBuilderFactory builderFactory) {
    return build(builderFactory, builderFactory.createObjectBuilder())
            .build();
}
项目:schematica    文件:SchematicaJsonProvider.java   
@Override
public JsonBuilderFactory createBuilderFactory( Map<String, ?> config ) {
    return defaultProvider.createBuilderFactory(config);
}