@Override public void configure(final Env env, final Config config, final Binder binder) { JsonbConfig jsonbConfig = new JsonbConfig(); if (configurer != null) { configurer.accept(jsonbConfig, config); } Jsonb jsonb = JsonbBuilder.create(jsonbConfig); binder.bind(Jsonb.class).toInstance(jsonb); Multibinder.newSetBinder(binder, Parser.class).addBinding() .toInstance(new YassonParser(type, jsonb)); Multibinder.newSetBinder(binder, Renderer.class).addBinding() .toInstance(new YassonRenderer(type, jsonb)); }
public OpenAPI loadDefaultApi() { final ClassLoader loader = Thread.currentThread().getContextClassLoader(); return Stream.of("", "/").map(prefix -> prefix + "META-INF/openapi.json") .map(it -> ofNullable(loader.getResourceAsStream(it)).orElseGet(() -> context.getResourceAsStream(it))) .filter(Objects::nonNull).findFirst().map(r -> { try (final Jsonb jsonb = JsonbBuilder.create(new JsonbConfig() .setProperty("johnzon.interfaceImplementationMapping", ApiBindings.get())); final InputStream stream = r) { return jsonb.fromJson(stream, OpenAPIImpl.class); } catch (final Exception e) { throw new IllegalStateException(e); } }).map(OpenAPI.class::cast) .orElseGet(() -> Stream.of("", "/").map(prefix -> prefix + "META-INF/openapi.") .flatMap(p -> Stream.of(p + "yaml", p + "yml")) .map(it -> ofNullable(loader.getResourceAsStream(it)).orElseGet(() -> context.getResourceAsStream(it))) .filter(Objects::nonNull).findFirst().map(this::loadFromYaml).orElseGet(OpenAPIImpl::new)); }
@PostConstruct private void init() { defaultMapper = JsonbBuilder.create(new JsonbConfig().withPropertyOrderStrategy(PropertyOrderStrategy.LEXICOGRAPHICAL)); }
public UiSpecService(final Client client) { this.client = client; this.jsonb = JsonbBuilder.create(new JsonbConfig().setProperty("johnzon.cdi.activated", false)); this.closeJsonb = true; }
private static Jsonb newJsonb() { return JsonbBuilder .create(new JsonbConfig() .withPropertyOrderStrategy(PropertyOrderStrategy.LEXICOGRAPHICAL) .withFormatting(true)); }
@Override // for debug purposes, don't use it for anything else public String toString() { try (final Jsonb jsonb = JsonbBuilder .create(new JsonbConfig().withFormatting(true).setProperty("johnzon.cdi.activated", false))) { return new RecordConverters() .toType(this, JsonObject.class, () -> Json.createBuilderFactory(emptyMap()), JsonProvider::provider, () -> jsonb) .toString(); } catch (final Exception e) { return super.toString(); } }
.getContextClassLoader() .getResourceAsStream("META-INF/resources/documentation/openapi.json"); final Jsonb jsonb = JsonbBuilder.create(new JsonbConfig())) { final String newJson = IO.slurp(source); String oldJson = !output.exists() ? "{}" : String.join("\n", Files.readAllLines(output.toPath()));
.create(new JsonbConfig().withPropertyOrderStrategy(PropertyOrderStrategy.LEXICOGRAPHICAL))) { final Map<String, List<JsonObject>> byVersion = updates.stream().map(f -> { try {
private Object map(final Object next) { if (next == null || Record.class.isInstance(next)) { // directly ok return next; } if (String.class.isInstance(next) || next.getClass().isPrimitive()) { // primitives return next; } if (jsonb == null) { synchronized (this) { if (jsonb == null) { jsonb = JsonbBuilder .create(new JsonbConfig() .withAdapters(new MultipleFormatDateAdapter()) .setProperty("johnzon.cdi.activated", false)); } } } return new RecordConverters() .toRecord(next, () -> jsonb, () -> ComponentManager.instance().getRecordBuilderFactoryProvider().apply(null)); } }
config = new JsonbConfig();
if (jsonb == null) { jsonb = JsonbBuilder .create(new JsonbConfig() .withAdapters(new MultipleFormatDateAdapter()) .setProperty("johnzon.cdi.activated", false));
config = new JsonbConfig();
.withConfig(new JsonbConfig() .setProperty("johnzon.cdi.activated", false) .setProperty("johnzon.attributeOrder", String.CASE_INSENSITIVE_ORDER))
private Jsonb jsonb() { if (jsonb == null) { synchronized (this) { if (jsonb == null) { jsonb = ContainerFinder.Instance.get().find(plugin()).findService(Jsonb.class); } if (jsonb == null) { // for tests mainly jsonb = JsonbBuilder .create(new JsonbConfig() .withAdapters(new MultipleFormatDateAdapter()) .withBinaryDataStrategy(BinaryDataStrategy.BASE_64)); } } } return jsonb; }
synchronized Jsonb jsonb() { if (jsonb == null) { jsonb = manager .getJsonbProvider() .create() .withProvider(new PreComputedJsonpProvider("test", manager.getJsonpProvider(), manager.getJsonpParserFactory(), manager.getJsonpWriterFactory(), manager.getJsonpBuilderFactory(), manager.getJsonpGeneratorFactory(), manager.getJsonpReaderFactory())) // reuses the same memory buffers .withConfig(new JsonbConfig().setProperty("johnzon.cdi.activated", false)) .build(); } return jsonb; }