javax.json.stream.JsonGeneratorFactory Java Examples

The following examples show how to use javax.json.stream.JsonGeneratorFactory. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JsonSecurityMessage.java    From aceql-http with GNU Lesser General Public License v2.1 7 votes vote down vote up
/**
    * Builds a security error message in JSON format for Statements
    * 
    * @param sqlOrder
    * @param errorMessage
    * @param doPrettyPrinting
    * @return
    */
   public static String statementNotAllowedBuild(String sqlOrder,
    String errorMessage, boolean doPrettyPrinting) {

try {
    JsonGeneratorFactory jf = JsonUtil
	    .getJsonGeneratorFactory(doPrettyPrinting);

    ByteArrayOutputStream out = new ByteArrayOutputStream();

    JsonGenerator gen = jf.createGenerator(out);
    gen.writeStartObject();
    gen.write(Tag.PRODUCT_SECURITY, errorMessage);
    gen.write("SQL order", sqlOrder);
    gen.writeEnd();
    gen.close();
    return out.toString("UTF-8");
} catch (Exception e) {
    String returnString = Tag.PRODUCT_SECURITY + " " + errorMessage
	    + " " + sqlOrder;
    return returnString;
}

   }
 
Example #2
Source File: JSONDomainFacade.java    From jcypher with Apache License 2.0 6 votes vote down vote up
/**
 * Answer a JSON object containing the domain name
 * @return
 */
public String getDomainName() {
	DomainModel model = ((IIntDomainAccess)this.domainAccess).getInternalDomainAccess().getDomainModel();
	StringWriter sw = new StringWriter();
	JsonGenerator generator;
	if (this.prettyFormat != Format.NONE) {
		JsonGeneratorFactory gf = JSONWriter.getPrettyGeneratorFactory();
		generator = gf.createGenerator(sw);
	} else
		generator = Json.createGenerator(sw);
	
	generator.writeStartObject();
	generator.write("domainName", model.getDomainName());
	generator.writeEnd();

	generator.flush();
	return sw.toString();
}
 
Example #3
Source File: JSONConverter.java    From jcypher with Apache License 2.0 6 votes vote down vote up
/**
 * Answer a JSON representation of a recorded query
 * @param query
 * @return
 */
public String toJSON(RecordedQuery query) {
	StringWriter sw = new StringWriter();
	JsonGenerator generator;
	if (this.prettyFormat != Format.NONE) {
		JsonGeneratorFactory gf = JSONWriter.getPrettyGeneratorFactory();
		generator = gf.createGenerator(sw);
	} else
		generator = Json.createGenerator(sw);
	
	generator.writeStartObject();
	writeQuery(query, generator);
	generator.writeEnd();

	generator.flush();
	return sw.toString();
}
 
Example #4
Source File: PluralRecordExtension.java    From component-runtime with Apache License 2.0 6 votes vote down vote up
private Jsonb createPojoJsonb() {
    final JsonbBuilder jsonbBuilder = JsonbBuilder.newBuilder().withProvider(new JsonProviderImpl() {

        @Override
        public JsonGeneratorFactory createGeneratorFactory(final Map<String, ?> config) {
            return new RecordJsonGenerator.Factory(() -> new RecordBuilderFactoryImpl("test"),
                    () -> getJsonb(createPojoJsonb()), config);
        }
    });
    try { // to passthrough the writer, otherwise RecoderJsonGenerator is broken
        final Field mapper = jsonbBuilder.getClass().getDeclaredField("builder");
        if (!mapper.isAccessible()) {
            mapper.setAccessible(true);
        }
        MapperBuilder.class.cast(mapper.get(jsonbBuilder)).setDoCloseOnStreams(true);
    } catch (final Exception e) {
        throw new IllegalStateException(e);
    }
    return jsonbBuilder.build();
}
 
Example #5
Source File: JSONDBFacade.java    From jcypher with Apache License 2.0 6 votes vote down vote up
/**
 * Answer a JSON representation of the available domains in the database
 * @return
 */
public String getDomains() {
	StringWriter sw = new StringWriter();
	JsonGenerator generator;
	if (this.prettyFormat != Format.NONE) {
		JsonGeneratorFactory gf = JSONWriter.getPrettyGeneratorFactory();
		generator = gf.createGenerator(sw);
	} else
		generator = Json.createGenerator(sw);
	
	generator.writeStartArray();
	List<String> doms = DomainInformation.availableDomains(dbAccess);
	for (String dom : doms) {
		generator.write(dom);
	}
	generator.writeEnd();

	generator.flush();
	return sw.toString();
}
 
Example #6
Source File: DefaultServices.java    From component-runtime with Apache License 2.0 6 votes vote down vote up
public static Object lookup(final String type) {
    if (type.equals(JsonBuilderFactory.class.getName())) {
        return ComponentManager.instance().getJsonpBuilderFactory();
    }
    if (type.equals(JsonReaderFactory.class.getName())) {
        return ComponentManager.instance().getJsonpReaderFactory();
    }
    if (type.equals(JsonGeneratorFactory.class.getName())) {
        return ComponentManager.instance().getJsonpGeneratorFactory();
    }
    if (type.equals(JsonParserFactory.class.getName())) {
        return ComponentManager.instance().getJsonpParserFactory();
    }
    if (type.equals(JsonWriterFactory.class.getName())) {
        return ComponentManager.instance().getJsonpWriterFactory();
    }
    if (type.equals(RecordBuilderFactory.class.getName())) {
        final Function<String, RecordBuilderFactory> provider =
                ComponentManager.instance().getRecordBuilderFactoryProvider();
        return provider.apply(null);
    }
    throw new IllegalArgumentException(type + " can't be a global service, didn't you pass a null plugin?");
}
 
Example #7
Source File: JSONDomainFacade.java    From jcypher with Apache License 2.0 6 votes vote down vote up
/**
 * Answer a JSON representation of the domain model
 * @return
 */
public String getDomainModel() {
	DomainModel model = ((IIntDomainAccess)this.domainAccess).getInternalDomainAccess().getDomainModel();
	StringWriter sw = new StringWriter();
	JsonGenerator generator;
	if (this.prettyFormat != Format.NONE) {
		JsonGeneratorFactory gf = JSONWriter.getPrettyGeneratorFactory();
		generator = gf.createGenerator(sw);
	} else
		generator = Json.createGenerator(sw);
	
	generator.writeStartObject();
	generator.write("domainName", model.getDomainName());
	writeModel(model, generator);
	generator.writeEnd();

	generator.flush();
	return sw.toString();
}
 
Example #8
Source File: JsonExample.java    From aceql-http with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
    * @param args
    * @throws IOException
    */
   public static void main(String[] args) throws IOException {
StringWriter writer = new StringWriter();

JsonGeneratorFactory jf = JsonUtil.getJsonGeneratorFactory(true);
JsonGenerator gen = jf.createGenerator(writer);

gen.writeStartObject().write("firstName", "Duke")
	.write("lastName", "Java").write("age", 18)
	.write("streetAddress", "100 Internet Dr")
	.write("city", "JavaTown").write("state", "JA")
	.write("postalCode", "12345")

	.writeStartArray("phoneNumbers").writeStartObject()
	.write("type", "mobile").write("number", "111-111-1111")
	.writeEnd().writeStartObject().write("type", "home")
	.write("number", "222-222-2222").writeEnd().writeEnd()

	.writeEnd();
gen.close();

System.out.println(writer.toString());

   }
 
Example #9
Source File: JsonOkReturn.java    From aceql-http with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
    * Build a Json with name and values from the passed map
    * 
    * @param namesAndValues
    *            the map of (name, value) to add to the JsonGenerator
    * @return
    */
   public static String build(Map<String, String> namesAndValues) {

if (namesAndValues == null) {
    throw new NullPointerException("namesAndValues is null");
}

JsonGeneratorFactory jf = JsonUtil
	.getJsonGeneratorFactory(JsonUtil.DEFAULT_PRETTY_PRINTING);

StringWriter sw = new StringWriter();
JsonGenerator gen = jf.createGenerator(sw);

gen.writeStartObject().write("status", "OK");

for (Map.Entry<String, String> entry : namesAndValues.entrySet()) {

    //System.out.println(entry.getKey() + "/" + entry.getValue());
    gen.write(entry.getKey(), entry.getValue());
}

gen.writeEnd();
gen.close();

return sw.toString();
   }
 
Example #10
Source File: JsonOkReturn.java    From aceql-http with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
    * Returns a name and a value after the OK
    * 
    * @return just OK
    */
   public static String build(String name, String value) {

if (name == null) {
    throw new NullPointerException("name is null");
}
if (value == null) {
    throw new NullPointerException("value is null");
}

JsonGeneratorFactory jf = JsonUtil
	.getJsonGeneratorFactory(JsonUtil.DEFAULT_PRETTY_PRINTING);

StringWriter sw = new StringWriter();
JsonGenerator gen = jf.createGenerator(sw);

gen.writeStartObject().write("status", "OK").write(name, value)
	.writeEnd();
gen.close();

return sw.toString();
   }
 
Example #11
Source File: JsonErrorReturn.java    From aceql-http with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
    * Builds the error message
    *
    * @return the error message
    */
   public String build() {

JsonGeneratorFactory jf = JsonUtil
	.getJsonGeneratorFactory(JsonUtil.DEFAULT_PRETTY_PRINTING);

StringWriter sw = new StringWriter();
JsonGenerator gen = jf.createGenerator(sw);

gen.writeStartObject().write("status", "FAIL").write("error_type",
	errorType);

if (errorMessage != null) {
    gen.write("error_message", errorMessage);
} else {
    gen.write("error_message", JsonValue.NULL);
}

if (stackTrace != null) {
    gen.write("stack_trace", stackTrace);
    System.err.println(stackTrace);
}

gen.write("http_status", httpStatus);

gen.writeEnd();
gen.close();

String doc = sw.toString();

if (LOG_JSON_ERROR) {
    System.err.println(doc);
}

return doc;
   }
 
Example #12
Source File: JsonUtil.java    From aceql-http with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
    * JsonGeneratorFactory getter with pretty printing on/off
    *
    * @param prettyPrintingif
    *            true, JSON will be pretty printed
    * @return
    */
   public static JsonGeneratorFactory getJsonGeneratorFactory(
    boolean prettyPrinting) {
Map<String, Object> properties = new HashMap<>(1);
if (prettyPrinting) {
    // Putting any value sets the pretty printing to true... So test
    // must be done
    properties.put(JsonGenerator.PRETTY_PRINTING, prettyPrinting);
}

JsonGeneratorFactory jf = Json.createGeneratorFactory(properties);
return jf;
   }
 
Example #13
Source File: JsonOkReturn.java    From aceql-http with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
    * Returns just OK
    * 
    * @return just OK
    */
   public static String build() {

JsonGeneratorFactory jf = JsonUtil
	.getJsonGeneratorFactory(JsonUtil.DEFAULT_PRETTY_PRINTING);

StringWriter sw = new StringWriter();
JsonGenerator gen = jf.createGenerator(sw);

gen.writeStartObject().write("status", "OK").writeEnd();
gen.close();

return sw.toString();
   }
 
Example #14
Source File: JSONWriter.java    From jcypher with Apache License 2.0 5 votes vote down vote up
public static JsonGeneratorFactory getPrettyGeneratorFactory() {
	if (prettyGeneratorFactory == null) {
		HashMap<String, Object> prettyConfigMap = new HashMap<String, Object>();
		prettyConfigMap.put(JsonGenerator.PRETTY_PRINTING, Boolean.TRUE);
		prettyGeneratorFactory = Json.createGeneratorFactory(prettyConfigMap);
	}
	return prettyGeneratorFactory;
}
 
Example #15
Source File: JSONWriter.java    From jcypher with Apache License 2.0 5 votes vote down vote up
public static String toJSON(PreparedQuery preparedQuery) {
	if (preparedQuery.hasdSLParams()) { // parameters part of json must be recreated
		WriterContext context = new WriterContext();
		PQContext pqContext = preparedQuery.getContext();
		QueryParam.setExtractParams(pqContext.extractParams, context);
		context.cypherFormat = pqContext.cypherFormat;
		String cypher = preparedQuery.getCypher();
		
		StringWriter sw = new StringWriter();
		JsonGenerator generator;
		if (context.cypherFormat != Format.NONE) {
			JsonGeneratorFactory gf = getPrettyGeneratorFactory();
			generator = gf.createGenerator(sw);
		} else
			generator = Json.createGenerator(sw);
		
		ContextAccess.setUseTransactionalEndpoint(pqContext.useTransationalEndpoint, context);
		ContextAccess.setResultDataContents(context, pqContext.resultDataContents);
		context.queryParams = pqContext.queryParams;
		
		generator.writeStartObject();
		if (pqContext.useTransationalEndpoint)
			writeStatements(new Statement[] {new Statement(context, cypher)}, generator);
		else
			writeQuery("query", cypher, context, generator);
		generator.writeEnd();

		generator.flush();
		context.buffer.append(sw.getBuffer());
		return context.buffer.toString();
	} else
		return preparedQuery.getJson();
}
 
Example #16
Source File: JsonFormatter.java    From jboss-logmanager-ext with Apache License 2.0 5 votes vote down vote up
@Override
protected Generator createGenerator(final Writer writer) {
    final JsonGeneratorFactory factory;
    synchronized (config) {
        factory = this.factory;
    }
    return new FormatterJsonGenerator(factory.createGenerator(writer));
}
 
Example #17
Source File: JSONWriter.java    From jcypher with Apache License 2.0 4 votes vote down vote up
public static String toJSON(PreparedQueries preparedQueries) {
	if (preparedQueries.hasdSLParams()) { // parameters part of json must be recreated
		WriterContext context = new WriterContext();
		List<PreparedQuery> prepQs = preparedQueries.getPreparedQueries();
		if (prepQs.isEmpty())
			return new String();
		PreparedQuery prepQ = prepQs.get(0);
		PQContext pqContext = prepQ.getContext();
		List<Statement> statements = new ArrayList<Statement>(prepQs.size());
		Format cf = pqContext.cypherFormat;
		pqContext.fillContext(context);
		context.cypherFormat = Format.NONE;
		// needed for multiple statements
		ContextAccess.setUseTransactionalEndpoint(true, context);
		for (PreparedQuery pq : prepQs) {
			WriterContext ctxt = new WriterContext();
			PQContext pqCtxt = pq.getContext();
			pqCtxt.fillContext(ctxt);
			
			String cypher = pq.getCypher();
			statements.add(new Statement(ctxt, cypher));
		}
		context.cypherFormat = cf;
		
		StringWriter sw = new StringWriter();
		JsonGenerator generator;
		if (context.cypherFormat != Format.NONE) {
			JsonGeneratorFactory gf = getPrettyGeneratorFactory();
			generator = gf.createGenerator(sw);
		} else
			generator = Json.createGenerator(sw);
		
		generator.writeStartObject();
		Statement[] statementsArray = statements.toArray(new Statement[statements.size()]);
		writeStatements(statementsArray, generator);
		generator.writeEnd();

		generator.flush();
		context.buffer.append(sw.getBuffer());
		preparedQueries.setJson(context.buffer.toString());
		return preparedQueries.getJson();
	} else
		return preparedQueries.getJson();
}
 
Example #18
Source File: JSONWriter.java    From jcypher with Apache License 2.0 4 votes vote down vote up
public static void toJSON(JcQuery query, WriterContext context) {
	PreparedQuery prepQ = new PreparedQuery();
	context.preparedQuery = prepQ;
	PQContext pqContext = prepQ.getContext();
	pqContext.cypherFormat = context.cypherFormat;
	context.cypherFormat = Format.NONE;
	boolean extract = QueryParam.isExtractParams(context);
	pqContext.extractParams = query.isExtractParams();
	QueryParam.setExtractParams(query.isExtractParams(), context);
	CypherWriter.toCypherExpression(query, context);
	context.cypherFormat = pqContext.cypherFormat;
	String cypher = context.buffer.toString();
	reInitContext(context);
	
	prepQ.setCypher(cypher);
	
	StringWriter sw = new StringWriter();
	JsonGenerator generator;
	if (context.cypherFormat != Format.NONE) {
		JsonGeneratorFactory gf = getPrettyGeneratorFactory();
		generator = gf.createGenerator(sw);
	} else
		generator = Json.createGenerator(sw);
	
	pqContext.useTransationalEndpoint = ContextAccess.useTransationalEndpoint(context);
	pqContext.resultDataContents = ContextAccess.getResultDataContents(context);
	pqContext.queryParams = QueryParamSet.getQueryParams(context);
	
	generator.writeStartObject();
	if (ContextAccess.useTransationalEndpoint(context))
		writeStatements(new Statement[] {new Statement(context, cypher)}, generator);
	else
		writeQuery("query", cypher, context, generator);
	generator.writeEnd();

	generator.flush();
	context.buffer.append(sw.getBuffer());
	
	// reset to original
	QueryParam.setExtractParams(extract, context);
	prepQ.setJson(context.buffer.toString());
}
 
Example #19
Source File: JSONWriter.java    From jcypher with Apache License 2.0 4 votes vote down vote up
public static void toJSON(List<JcQuery> queries, WriterContext context) {
	List<Statement> statements = new ArrayList<Statement>(queries.size());
	PreparedQueries prepQs = new PreparedQueries();
	context.preparedQuery = prepQs;
	Format cf = context.cypherFormat;
	context.cypherFormat = Format.NONE;
	boolean useTxEndpoint = ContextAccess.useTransationalEndpoint(context);
	// needed for multiple statements
	ContextAccess.setUseTransactionalEndpoint(true, context);
	boolean extract = QueryParam.isExtractParams(context);
	for (JcQuery query : queries) {
		PreparedQuery prepQ = new PreparedQuery();
		prepQs.add(prepQ);
		PQContext pqContext = prepQ.getContext();
		pqContext.cypherFormat = cf;
		pqContext.extractParams = query.isExtractParams();
		pqContext.useTransationalEndpoint = ContextAccess.useTransationalEndpoint(context);
		pqContext.resultDataContents = ContextAccess.getResultDataContents(context);
		
		WriterContext ctxt = ContextAccess.cloneContext(context);
		ctxt.preparedQuery = prepQs; // needed to mark if there are dynamic parameters
		QueryParam.setExtractParams(query.isExtractParams(), ctxt);
		CypherWriter.toCypherExpression(query, ctxt);
		String cypher = ctxt.buffer.toString();
		prepQ.setCypher(cypher);
		pqContext.queryParams = QueryParamSet.getQueryParams(ctxt);
		reInitContext(ctxt);
		statements.add(new Statement(ctxt, cypher));
	}
	context.cypherFormat = cf;
	
	StringWriter sw = new StringWriter();
	JsonGenerator generator;
	if (context.cypherFormat != Format.NONE) {
		JsonGeneratorFactory gf = getPrettyGeneratorFactory();
		generator = gf.createGenerator(sw);
	} else
		generator = Json.createGenerator(sw);
	
	generator.writeStartObject();
	Statement[] statementsArray = statements.toArray(new Statement[statements.size()]);
	writeStatements(statementsArray, generator);
	generator.writeEnd();

	generator.flush();
	context.buffer.append(sw.getBuffer());
	
	// reset to original
	QueryParam.setExtractParams(extract, context);
	ContextAccess.setUseTransactionalEndpoint(useTxEndpoint, context);
	prepQs.setJson(context.buffer.toString());
}
 
Example #20
Source File: JsonProvider.java    From baratine with GNU General Public License v2.0 4 votes vote down vote up
public abstract JsonGeneratorFactory
createGeneratorFactory(JsonConfiguration config);
 
Example #21
Source File: JsonLoader.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
public static JsonGeneratorFactory createGeneratorFactory(Map<String, ?> config) {
   return provider.createGeneratorFactory(config);
}
 
Example #22
Source File: JavaxJsonFactories.java    From attic-polygene-java with Apache License 2.0 4 votes vote down vote up
@Override
public JsonGeneratorFactory generatorFactory()
{
    return generatorFactory;
}
 
Example #23
Source File: ConfigurableBus.java    From openwebbeans-meecrowave with Apache License 2.0 4 votes vote down vote up
@Override
public JsonGeneratorFactory createGeneratorFactory(final Map<String, ?> config) {
    return provider.createGeneratorFactory(config);
}
 
Example #24
Source File: FHIRJsonGenerator.java    From FHIR with Apache License 2.0 4 votes vote down vote up
private static JsonGeneratorFactory createPrettyPrintingGeneratorFactory() {
    Map<java.lang.String, Object> properties = new HashMap<>(1);
    properties.put(JsonGenerator.PRETTY_PRINTING, true);
    return Json.createGeneratorFactory(properties);
}
 
Example #25
Source File: Json.java    From baratine with GNU General Public License v2.0 4 votes vote down vote up
public static JsonGeneratorFactory createGeneratorFactory(JsonConfiguration config)
{
  return getProvider().createGeneratorFactory(config);
}
 
Example #26
Source File: Json.java    From baratine with GNU General Public License v2.0 4 votes vote down vote up
public static JsonGeneratorFactory createGeneratorFactory()
{
  return getProvider().createGeneratorFactory();
}
 
Example #27
Source File: DefaultServiceProvider.java    From component-runtime with Apache License 2.0 4 votes vote down vote up
private Object doLookup(final String id, final ClassLoader loader,
        final Supplier<List<InputStream>> localConfigLookup, final Function<String, Path> resolver,
        final Class<?> api, final AtomicReference<Map<Class<?>, Object>> services) {
    if (JsonProvider.class == api) {
        return new PreComputedJsonpProvider(id, jsonpProvider, jsonpParserFactory, jsonpWriterFactory,
                jsonpBuilderFactory, jsonpGeneratorFactory, jsonpReaderFactory);
    }
    if (JsonBuilderFactory.class == api) {
        return javaProxyEnricherFactory
                .asSerializable(loader, id, JsonBuilderFactory.class.getName(), jsonpBuilderFactory);
    }
    if (JsonParserFactory.class == api) {
        return javaProxyEnricherFactory
                .asSerializable(loader, id, JsonParserFactory.class.getName(), jsonpParserFactory);
    }
    if (JsonReaderFactory.class == api) {
        return javaProxyEnricherFactory
                .asSerializable(loader, id, JsonReaderFactory.class.getName(), jsonpReaderFactory);
    }
    if (JsonWriterFactory.class == api) {
        return javaProxyEnricherFactory
                .asSerializable(loader, id, JsonWriterFactory.class.getName(), jsonpWriterFactory);
    }
    if (JsonGeneratorFactory.class == api) {
        return javaProxyEnricherFactory
                .asSerializable(loader, id, JsonGeneratorFactory.class.getName(), jsonpGeneratorFactory);
    }
    if (Jsonb.class == api) {
        final JsonbBuilder jsonbBuilder = createPojoJsonbBuilder(id,
                Lazy
                        .lazy(() -> Jsonb.class
                                .cast(doLookup(id, loader, localConfigLookup, resolver, Jsonb.class, services))));
        return new GenericOrPojoJsonb(id, jsonbProvider
                .create()
                .withProvider(jsonpProvider) // reuses the same memory buffering
                .withConfig(jsonbConfig)
                .build(), jsonbBuilder.build());
    }
    if (LocalConfiguration.class == api) {
        final List<LocalConfiguration> containerConfigurations = new ArrayList<>(localConfigurations);
        if (!Boolean.getBoolean("talend.component.configuration." + id + ".ignoreLocalConfiguration")) {
            final Stream<InputStream> localConfigs = localConfigLookup.get().stream();
            final Properties aggregatedLocalConfigs = aggregateConfigurations(localConfigs);
            if (!aggregatedLocalConfigs.isEmpty()) {
                containerConfigurations.add(new PropertiesConfiguration(aggregatedLocalConfigs));
            }
        }
        return new LocalConfigurationService(containerConfigurations, id);
    }
    if (RecordBuilderFactory.class == api) {
        return recordBuilderFactoryProvider.apply(id);
    }
    if (ProxyGenerator.class == api) {
        return proxyGenerator;
    }
    if (LocalCache.class == api) {
        final LocalCacheService service =
                new LocalCacheService(id, System::currentTimeMillis, this.executorService);
        Injector.class.cast(services.get().get(Injector.class)).inject(service);
        return service;
    }
    if (Injector.class == api) {
        return new InjectorImpl(id, reflections, proxyGenerator, services.get());
    }
    if (HttpClientFactory.class == api) {
        return new HttpClientFactoryImpl(id, reflections, Jsonb.class.cast(services.get().get(Jsonb.class)),
                services.get());
    }
    if (Resolver.class == api) {
        return new ResolverImpl(id, resolver);
    }
    if (ObjectFactory.class == api) {
        return new ObjectFactoryImpl(id, propertyEditorRegistry);
    }
    if (RecordPointerFactory.class == api) {
        return new RecordPointerFactoryImpl(id);
    }
    if (ContainerInfo.class == api) {
        return new ContainerInfo(id);
    }
    if (RecordService.class == api) {
        return new RecordServiceImpl(id, recordBuilderFactoryProvider.apply(id), () -> jsonpBuilderFactory,
                () -> jsonpProvider,
                Lazy
                        .lazy(() -> Jsonb.class
                                .cast(doLookup(id, loader, localConfigLookup, resolver, Jsonb.class, services))));
    }
    return null;
}
 
Example #28
Source File: PreComputedJsonpProvider.java    From component-runtime with Apache License 2.0 4 votes vote down vote up
@Override
public JsonGeneratorFactory createGeneratorFactory(final Map<String, ?> config) {
    return generatorFactory;
}
 
Example #29
Source File: FHIRJsonGenerator.java    From FHIR with Apache License 2.0 4 votes vote down vote up
private JsonGeneratorFactory getGeneratorFactory() {
    return prettyPrinting ? PRETTY_PRINTING_GENERATOR_FACTORY : GENERATOR_FACTORY;
}
 
Example #30
Source File: AuspiceGenerator.java    From beast-mcmc with GNU Lesser General Public License v2.1 3 votes vote down vote up
private void writeTreeJSON(String filename, RootedTree tree) throws IOException {
    FileWriter writer = new FileWriter(filename);

    HashMap<String, Object> config = new HashMap<>();
    config.put(JsonGenerator.PRETTY_PRINTING, true);

    JsonGeneratorFactory factory = Json.createGeneratorFactory(config);

    JsonGenerator generator = factory.createGenerator(writer);
    currentYValue = 0;

    writeNode(generator, tree, tree.getRootNode());

    generator.close();
}