Class MicronautJsonbProvider.MicronautJsonb

java.lang.Object
io.micronaut.serde.jsonb.MicronautJsonbProvider.MicronautJsonb
All Implemented Interfaces:
jakarta.json.bind.Jsonb, AutoCloseable
Enclosing class:
MicronautJsonbProvider

protected static class MicronautJsonbProvider.MicronautJsonb extends Object implements jakarta.json.bind.Jsonb
Since:
3.1.0
  • Field Details

    • mapper

      protected final ObjectMapper mapper
    • registry

      protected final SerdeRegistry registry
    • jsonFactory

      protected final tools.jackson.core.json.JsonFactory jsonFactory
    • charset

      protected final Charset charset
    • prettyPrint

      protected final boolean prettyPrint
    • strictIJson

      protected final boolean strictIJson
    • binaryDataStrategy

      protected final String binaryDataStrategy
    • serdeConfiguration

      protected final @Nullable SerdeConfiguration serdeConfiguration
  • Constructor Details

  • Method Details

    • generatedSerdeCache

      protected static <K,V> ConcurrentMap<K,V> generatedSerdeCache()
      Creates a bounded cache for per-mapper generated Serde capability checks. The cache is intentionally small because it protects hot reflection-provider routing paths, not application domain data.
      Type Parameters:
      K - The cache key type
      V - The cache value type
      Returns:
      A concurrent bounded cache
    • fromJson

      public <T> @Nullable T fromJson(String str, Class<T> type) throws jakarta.json.bind.JsonbException
      Specified by:
      fromJson in interface jakarta.json.bind.Jsonb
      Throws:
      jakarta.json.bind.JsonbException
    • fromJson

      public <T> @Nullable T fromJson(String str, Type runtimeType) throws jakarta.json.bind.JsonbException
      Specified by:
      fromJson in interface jakarta.json.bind.Jsonb
      Throws:
      jakarta.json.bind.JsonbException
    • fromJson

      public <T> @Nullable T fromJson(Reader reader, Class<T> type) throws jakarta.json.bind.JsonbException
      Specified by:
      fromJson in interface jakarta.json.bind.Jsonb
      Throws:
      jakarta.json.bind.JsonbException
    • fromJson

      public <T> @Nullable T fromJson(Reader reader, Type runtimeType) throws jakarta.json.bind.JsonbException
      Specified by:
      fromJson in interface jakarta.json.bind.Jsonb
      Throws:
      jakarta.json.bind.JsonbException
    • fromJson

      public <T> @Nullable T fromJson(InputStream stream, Class<T> type) throws jakarta.json.bind.JsonbException
      Specified by:
      fromJson in interface jakarta.json.bind.Jsonb
      Throws:
      jakarta.json.bind.JsonbException
    • fromJson

      public <T> @Nullable T fromJson(InputStream stream, Type runtimeType) throws jakarta.json.bind.JsonbException
      Specified by:
      fromJson in interface jakarta.json.bind.Jsonb
      Throws:
      jakarta.json.bind.JsonbException
    • toJson

      public String toJson(Object object) throws jakarta.json.bind.JsonbException
      Specified by:
      toJson in interface jakarta.json.bind.Jsonb
      Throws:
      jakarta.json.bind.JsonbException
    • toJson

      public String toJson(Object object, Type runtimeType) throws jakarta.json.bind.JsonbException
      Specified by:
      toJson in interface jakarta.json.bind.Jsonb
      Throws:
      jakarta.json.bind.JsonbException
    • toJson

      public void toJson(Object object, Writer writer) throws jakarta.json.bind.JsonbException
      Specified by:
      toJson in interface jakarta.json.bind.Jsonb
      Throws:
      jakarta.json.bind.JsonbException
    • toJson

      public void toJson(Object object, Type runtimeType, Writer writer) throws jakarta.json.bind.JsonbException
      Specified by:
      toJson in interface jakarta.json.bind.Jsonb
      Throws:
      jakarta.json.bind.JsonbException
    • toJson

      public void toJson(Object object, OutputStream stream) throws jakarta.json.bind.JsonbException
      Specified by:
      toJson in interface jakarta.json.bind.Jsonb
      Throws:
      jakarta.json.bind.JsonbException
    • toJson

      public void toJson(Object object, Type runtimeType, OutputStream stream) throws jakarta.json.bind.JsonbException
      Specified by:
      toJson in interface jakarta.json.bind.Jsonb
      Throws:
      jakarta.json.bind.JsonbException
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
    • readString

      protected <T> @Nullable T readString(String str, io.micronaut.core.type.Argument<T> argument)
      Reads a JSON string through the generated deserializer path. Subclasses may override to provide non-generated fallback behavior.
      Type Parameters:
      T - The target type
      Parameters:
      str - The JSON string
      argument - The target argument
      Returns:
      The decoded value
    • readReader

      protected <T> @Nullable T readReader(Reader reader, io.micronaut.core.type.Argument<T> argument)
      Reads JSON from a reader through the generated deserializer path. Subclasses may override to provide non-generated fallback behavior while preserving streaming reads.
      Type Parameters:
      T - The target type
      Parameters:
      reader - The JSON reader
      argument - The target argument
      Returns:
      The decoded value
    • readStream

      protected <T> @Nullable T readStream(InputStream stream, io.micronaut.core.type.Argument<T> argument)
      Reads JSON from a stream through the generated deserializer path. Subclasses may override to provide non-generated fallback behavior while preserving streaming reads.
      Type Parameters:
      T - The target type
      Parameters:
      stream - The JSON input stream
      argument - The target argument
      Returns:
      The decoded value
    • readGenerated

      protected <T> @Nullable T readGenerated(io.micronaut.core.type.Argument<T> argument, MicronautJsonbProvider.ParserSource parserSource)
      Reads JSON from a parser source with the generated deserializer for the supplied argument.
      Type Parameters:
      T - The target type
      Parameters:
      argument - The target argument
      parserSource - The parser source
      Returns:
      The decoded value
    • canCreateGeneratedDeserializer

      protected <T> boolean canCreateGeneratedDeserializer(io.micronaut.core.type.Argument<T> argument)
      Checks whether a generated deserializer can be created for the argument.

      Registry lookup is intentionally cached because negative checks can be exception-heavy when JSON-B reflection fallback probes whether a value may use the generated path directly.

      Type Parameters:
      T - The target type
      Parameters:
      argument - The target argument
      Returns:
      Whether the deserializer can be created
    • canCreateGeneratedSerializer

      protected <T> boolean canCreateGeneratedSerializer(io.micronaut.core.type.Argument<T> argument)
      Checks whether a generated serializer can be created for the argument.

      Registry lookup is intentionally cached because negative checks can be exception-heavy when JSON-B reflection fallback probes whether a value may use the generated path directly.

      Type Parameters:
      T - The target type
      Parameters:
      argument - The target argument
      Returns:
      Whether the serializer can be created
    • writeGenerated

      protected <T> void writeGenerated(@Nullable T object, io.micronaut.core.type.Argument<T> argument, MicronautJsonbProvider.GeneratorSource generatorSource) throws IOException
      Writes JSON through the generated serializer path.
      Type Parameters:
      T - The value type
      Parameters:
      object - The value to write
      argument - The value argument
      generatorSource - The generator source
      Throws:
      IOException - If JSON writing fails
    • limits

      protected final LimitingStream.RemainingLimits limits()
    • validateStrictTopLevel

      protected void validateStrictTopLevel(@Nullable Object object)
      Validates strict I-JSON top-level constraints before writing.
      Parameters:
      object - The value to write
    • ensureGeneratedOnlyFeatures

      protected void ensureGeneratedOnlyFeatures()
      Ensures reflection-only JSON-B features are not used by the generated provider.
    • argument

      protected static io.micronaut.core.type.Argument<?> argument(Type runtimeType)
    • properties

      protected static Map<String,Object> properties(jakarta.json.bind.JsonbConfig config)
    • additionalPackages

      protected static String[] additionalPackages(jakarta.json.bind.JsonbConfig config)
    • mappedPropertyNamingStrategy

      protected static Optional<String> mappedPropertyNamingStrategy(jakarta.json.bind.JsonbConfig config)
    • propertyOrderStrategy

      protected static String propertyOrderStrategy(jakarta.json.bind.JsonbConfig config)
    • binaryDataStrategy

      protected static String binaryDataStrategy(jakarta.json.bind.JsonbConfig config)
    • charset

      protected static Charset charset(jakarta.json.bind.JsonbConfig config)
    • isJsonScalar

      protected static boolean isJsonScalar(Class<?> type)