org.apache.johnzon.mapper.MapperBuilder Java Examples

The following examples show how to use org.apache.johnzon.mapper.MapperBuilder. 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: DefaultServiceProvider.java    From component-runtime with Apache License 2.0 6 votes vote down vote up
private JsonbBuilder createPojoJsonbBuilder(final String id, final Supplier<Jsonb> jsonb) {
    final JsonbBuilder jsonbBuilder = JsonbBuilder
            .newBuilder()
            .withProvider(new PreComputedJsonpProvider(id, jsonpProvider, jsonpParserFactory, jsonpWriterFactory,
                    jsonpBuilderFactory,
                    new RecordJsonGenerator.Factory(Lazy.lazy(() -> recordBuilderFactoryProvider.apply(id)), jsonb,
                            emptyMap()),
                    jsonpReaderFactory))
            .withConfig(jsonbConfig);
    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;
}
 
Example #2
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 #3
Source File: LoadBalancerRegisterService.java    From microservice-with-jwt-and-microprofile with Apache License 2.0 5 votes vote down vote up
private String toJson() {
    final HostAutoProvisionItem item = new HostAutoProvisionItem();
    item.setActive(active);
    item.setEndpoint(serverUrl);
    item.setWeight(weight);

    final Mapper mapper = new MapperBuilder().setPretty(false).build();
    return mapper.writeObjectAsString(item);
}
 
Example #4
Source File: JohnzonBatcheeProvider.java    From incubator-batchee with Apache License 2.0 5 votes vote down vote up
public JohnzonBatcheeProvider() {
    super(new MapperBuilder()
            .addAdapter(new TimestampAdapter()) // backward compatibility
            .setAttributeOrder(new Comparator<String>() { // deterministic order (useful when used with scripts)
                @Override
                public int compare(final String o1, final String o2) {
                    return o1.compareTo(o2);
                }
            })
            .build(), null);
}
 
Example #5
Source File: TomEEJohnzonProvider.java    From tomee with Apache License 2.0 4 votes vote down vote up
public TomEEJohnzonProvider() {
    super(new MapperBuilder().setAccessModeName("both").build(), null);
}
 
Example #6
Source File: TomEEConfigurableJohnzon.java    From tomee with Apache License 2.0 4 votes vote down vote up
private MapperBuilder builder() {
    return localBuilder == null ? (localBuilder = MapperBuilder.class.cast(Reflections.get(this, "builder"))) : localBuilder;
}