All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.avaje.jsonb.inject.DefaultJsonbProvider Maven / Gradle / Ivy

The newest version!
package io.avaje.jsonb.inject;

import java.lang.reflect.Type;

import io.avaje.inject.BeanScopeBuilder;
import io.avaje.inject.spi.InjectPlugin;
import io.avaje.jsonb.Jsonb;
import io.avaje.json.stream.BufferRecycleStrategy;

/**
 * Plugin for avaje inject that provides a default Jsonb instance.
 */
public final class DefaultJsonbProvider implements InjectPlugin {

  @Override
  public Type[] provides() {
    return new Type[]{Jsonb.class};
  }

  @Override
  public void apply(BeanScopeBuilder builder) {
    builder.provideDefault(null, Jsonb.class, () -> {
      var props = builder.configPlugin();

      return Jsonb.builder()
        .failOnUnknown(props.equalTo("jsonb.deserialize.failOnUnknown", "true"))
        .mathTypesAsString(props.equalTo("jsonb.serialize.mathTypesAsString", "true"))
        .serializeEmpty(props.notEqualTo("jsonb.serialize.empty", "false"))
        .serializeNulls(props.equalTo("jsonb.serialize.nulls", "true"))
        .bufferRecycling(
          props
            .get("jsonb.bufferRecycling")
            .map(BufferRecycleStrategy::valueOf)
            .orElse(BufferRecycleStrategy.HYBRID_POOL))
        .build();
    });
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy