javax.json.JsonReaderFactory Java Examples
The following examples show how to use
javax.json.JsonReaderFactory.
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: DefaultServices.java From component-runtime with Apache License 2.0 | 6 votes |
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 #2
Source File: WeatherEventProvider.java From microprofile-rest-client with Apache License 2.0 | 6 votes |
@Override public WeatherEvent readFrom(Class<WeatherEvent> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException, WebApplicationException { JsonReaderFactory factory = Json.createReaderFactory(null); JsonReader reader = factory.createReader(entityStream); JsonObject jsonObject = reader.readObject(); String dateString = jsonObject.getString("date"); String description = jsonObject.getString("description"); DateFormat df = new SimpleDateFormat("yyyy-MM-dd"); try { WeatherEvent event = new WeatherEvent(df.parse(dateString), description); return event; } catch (ParseException ex) { throw new IOException(ex); } }
Example #3
Source File: ReflectionService.java From component-runtime with Apache License 2.0 | 5 votes |
private JsonValue createJsonValue(final Object value, final Map<Class<?>, Object> precomputed, final Function<Reader, JsonReader> fallbackReaderCreator) { final StringReader sr = new StringReader(String.valueOf(value).trim()); try (final JsonReader reader = ofNullable(precomputed.get(JsonReaderFactory.class)) .map(JsonReaderFactory.class::cast) .map(f -> f.createReader(sr)) .orElseGet(() -> fallbackReaderCreator.apply(sr))) { return reader.read(); } }
Example #4
Source File: SingerArgs.java From component-runtime with Apache License 2.0 | 5 votes |
private JsonObject readObject(final JsonReaderFactory factory, final String path) { final Path source = get(path); if (!Files.exists(source)) { throw new IllegalArgumentException("No file available at '" + source + "'"); } try (final JsonReader jsonReader = factory.createReader(Files.newInputStream(source))) { return jsonReader.readObject(); } catch (final IOException e) { throw new IllegalArgumentException(e); } }
Example #5
Source File: JsonpJsonObjectCoder.java From component-runtime with Apache License 2.0 | 5 votes |
public static JsonpJsonObjectCoder of(final String plugin) { if (plugin == null) { final ComponentManager instance = ComponentManager.instance(); return new JsonpJsonObjectCoder(instance.getJsonpReaderFactory(), instance.getJsonpWriterFactory()); } final LightContainer container = ContainerFinder.Instance.get().find(plugin); return new JsonpJsonObjectCoder(container.findService(JsonReaderFactory.class), container.findService(JsonWriterFactory.class)); }
Example #6
Source File: ResourceProcessor.java From FHIR with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws Exception { JsonReaderFactory jsonReaderFactory = Json.createReaderFactory(null); JsonWriterFactory jsonWriterFactory = Json.createWriterFactory(null); JsonBuilderFactory jsonBuilderFactory = Json.createBuilderFactory(null); File dir = new File("src/main/resources/hl7/fhir/us/davinci-pdex-plan-net/package/"); for (File file : dir.listFiles()) { String fileName = file.getName(); if (!fileName.endsWith(".json") || file.isDirectory()) { continue; } JsonObject jsonObject = null; try (BufferedReader reader = new BufferedReader(new FileReader(file))) { JsonReader jsonReader = jsonReaderFactory.createReader(reader); jsonObject = jsonReader.readObject(); JsonObjectBuilder jsonObjectBuilder = jsonBuilderFactory.createObjectBuilder(jsonObject); JsonObject text = jsonObject.getJsonObject("text"); if (text != null) { JsonObjectBuilder textBuilder = jsonBuilderFactory.createObjectBuilder(text); String div = text.getString("div"); div = div.replace("<p><pre>", "<pre>").replace("</pre></p>", "</pre>"); textBuilder.add("div", div); jsonObjectBuilder.add("text", textBuilder); } if (!jsonObject.containsKey("version")) { System.out.println("file: " + file + " does not have a version"); jsonObjectBuilder.add("version", "0.1.0"); } jsonObject = jsonObjectBuilder.build(); } try (FileWriter writer = new FileWriter(file)) { JsonWriter jsonWriter = jsonWriterFactory.createWriter(writer); jsonWriter.write(jsonObject); } } }
Example #7
Source File: LibrariesTest.java From appengine-plugins-core with Apache License 2.0 | 5 votes |
@Before public void parseJson() { oldCookieHandler = CookieHandler.getDefault(); // https://github.com/GoogleCloudPlatform/appengine-plugins-core/issues/822 CookieHandler.setDefault(new CookieManager()); JsonReaderFactory factory = Json.createReaderFactory(null); InputStream in = LibrariesTest.class.getResourceAsStream("libraries.json"); JsonReader reader = factory.createReader(in); apis = reader.readArray().toArray(new JsonObject[0]); }
Example #8
Source File: BeamIOTransformerTest.java From component-runtime with Apache License 2.0 | 4 votes |
private void scenario(final Scenario runnable) { final AtomicReference<ContainerFinder> containerFinder; try { final Field finder = ContainerFinder.Instance.class.getDeclaredField("FINDER"); if (!finder.isAccessible()) { finder.setAccessible(true); } containerFinder = (AtomicReference<ContainerFinder>) finder.get(null); final ContainerFinder oldContainerFinder = containerFinder.get(); try { final Thread thread = Thread.currentThread(); final ClassLoader originalLoader = thread.getContextClassLoader(); final String prefix = BeamIOTransformerTest.class.getName() + "$"; final Predicate<String> parentPredicate = it -> SetValidator.class.getName().equals(it) || !(it.startsWith(prefix) || it.startsWith(JdbcSource.class.getName())) || Pojo.class.getName().equals(it); try (final ConfigurableClassLoader loader = new ConfigurableClassLoader("test", new URL[] { jarLocation(BeamIOTransformerTest.class).toURI().toURL() }, originalLoader, parentPredicate, parentPredicate.negate(), new String[0], new String[0])) { // thread.setContextClassLoader(loader); // don't set it, this is what we test! final BeamIOTransformer transformer = new BeamIOTransformer(); loader.registerTransformer(transformer); containerFinder.set(plugin -> new LightContainer() { private final JavaProxyEnricherFactory factory = new JavaProxyEnricherFactory(); @Override public ClassLoader classloader() { return loader; } @Override public <T> T findService(final Class<T> key) { if (key == JsonReaderFactory.class) { return key .cast(factory .asSerializable(loader, "test", JsonReaderFactory.class.getName(), Json.createReaderFactory(emptyMap()))); } if (key == JsonWriterFactory.class) { return key .cast(factory .asSerializable(loader, "test", JsonWriterFactory.class.getName(), Json.createWriterFactory(emptyMap()))); } return null; } }); runnable.execute(transformer, loader); } catch (final Exception e) { doFail(e); } finally { thread.setContextClassLoader(originalLoader); } } finally { containerFinder.set(oldContainerFinder); } } catch (final Exception t) { doFail(t); } }
Example #9
Source File: JsonLoader.java From activemq-artemis with Apache License 2.0 | 4 votes |
public static JsonReaderFactory createReaderFactory(Map<String, ?> config) { return provider.createReaderFactory(config); }
Example #10
Source File: JavaxJsonFactories.java From attic-polygene-java with Apache License 2.0 | 4 votes |
@Override public JsonReaderFactory readerFactory() { return readerFactory; }
Example #11
Source File: ConfigurableBus.java From openwebbeans-meecrowave with Apache License 2.0 | 4 votes |
@Override public JsonReaderFactory createReaderFactory(final Map<String, ?> config) { return readerFactory; }
Example #12
Source File: ConfigurableBus.java From openwebbeans-meecrowave with Apache License 2.0 | 4 votes |
private DelegateJsonProvider(final JsonProvider provider, final JsonReaderFactory readerFactory, final JsonWriterFactory writerFactory) { this.provider = provider; this.readerFactory = readerFactory; this.writerFactory = writerFactory; }
Example #13
Source File: JsonpRuntime.java From jmespath-java with BSD 3-Clause "New" or "Revised" License | 4 votes |
public JsonpRuntime(RuntimeConfiguration configuration, JsonReaderFactory jsonReaderFactory) { super(configuration); this.jsonReaderFactory = jsonReaderFactory; }
Example #14
Source File: IndexedRecordToJson.java From component-runtime with Apache License 2.0 | 4 votes |
public Fn(final JsonReaderFactory factory) { this.factory = factory; }
Example #15
Source File: SingerArgs.java From component-runtime with Apache License 2.0 | 4 votes |
public SingerArgs(final String... args) { String config = null; String state = null; String catalog = null; String family = null; boolean discover = false; Map<String, String> otherArgs = new HashMap<>(); if (args == null || args.length == 0) { throw new IllegalArgumentException("No --config"); } for (int i = 0; i < args.length; i++) { final String arg = args[i]; if (arg == null) { continue; } switch (arg) { case "--config": config = args[i + 1]; i++; break; case "--state": state = args[i + 1]; i++; break; case "--catalog": catalog = args[i + 1]; i++; break; case "--component-family": family = args[i + 1]; i++; break; case "--discover": discover = true; break; default: if (arg.startsWith("--")) { otherArgs.put(arg, i + 1 < args.length ? args[i + 1] : "true"); i++; } // else fail? } } if (config == null) { throw new IllegalArgumentException("No --config"); } final JsonReaderFactory readerFactory = Json.createReaderFactory(emptyMap()); this.config = readObject(readerFactory, config); this.state = ofNullable(state).map(it -> readObject(readerFactory, it)).orElse(null); this.catalog = ofNullable(catalog).map(it -> readObject(readerFactory, it)).orElse(null); this.discover = discover; this.componentFamily = family; this.otherArgs = otherArgs; }
Example #16
Source File: DefaultServiceProvider.java From component-runtime with Apache License 2.0 | 4 votes |
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 #17
Source File: PreComputedJsonpProvider.java From component-runtime with Apache License 2.0 | 4 votes |
@Override public JsonReaderFactory createReaderFactory(final Map<String, ?> config) { return readerFactory; }
Example #18
Source File: JavaxJsonFactories.java From attic-polygene-java with Apache License 2.0 | votes |
JsonReaderFactory readerFactory();