Class NativeImageMetadataWriter

java.lang.Object
org.atmosphere.nativeimage.NativeImageMetadataWriter

public final class NativeImageMetadataWriter extends Object
Renders NativeImageMetadata as GraalVM's reachability-metadata.json.

The output is meant to be committed under META-INF/native-image/<group>/<artifact>/ in a shipped jar, where GraalVM picks it up automatically. That is what makes the SPI portable rather than Spring- and Quarkus-shaped: an application with neither integration module — a plain servlet container, embedded Jetty — still gets every reflective type the framework needs, with nothing to configure.

Written by hand rather than with a JSON library because atmosphere-runtime treats Jackson as optional, and a metadata generator that only works when an optional dependency happens to be present would defeat the purpose. The shape is small and fixed; the escaping below covers what class and resource names can legally contain.

  • Method Details

    • render

      public static String render(NativeImageMetadata metadata, String comment)
      Render metadata as GraalVM reachability JSON.

      Every type is registered with all declared constructors, methods and fields — matching what the Spring and Quarkus paths already request. These types are selected by configuration and constructed reflectively, so the framework cannot know which member it will need; narrowing the categories would trade image size for exactly the class of silent runtime failure this metadata exists to prevent.

      Parameters:
      metadata - the merged provider output
      comment - provenance line recorded in the file
      Returns:
      pretty-printed JSON with a trailing newline