Class JsonSchemaBeanGenerator

java.lang.Object
org.apache.juneau.bean.jsonschema.JsonSchemaBeanGenerator

public final class JsonSchemaBeanGenerator extends Object
Bridge for generating typed JsonSchema beans from Java types.

JsonSchemaGenerator in juneau-marshall produces JsonMap output. This class wraps that generator and converts the generated map into typed JsonSchema beans in juneau-bean-jsonschema.

Example:

// Default generation. JsonSchema s1 = JsonSchemaBeanGenerator.DEFAULT.generate(MyBean.class); // Custom generation with bean defs and descriptions. JsonSchema s2 = JsonSchemaBeanGenerator.create() .useBeanDefs() .addDescriptionsTo(TypeCategory.ANY) .build() .generate(MyBean.class);

  • Field Details

  • Method Details

    • create

      Creates a new builder.
    • generate

      public JsonSchema<?> generate(Type type)
      Generates a schema bean from a Java type.
      Parameters:
      type - The Java type. Must not be null, or an IllegalArgumentException is thrown.
      Returns:
      The generated schema bean, or null if a schema could not be generated for the type.
    • generate

      public JsonSchema<?> generate(Class<?> type)
      Generates a schema bean from a Java class.
      Parameters:
      type - The Java class. Must not be null, or an IllegalArgumentException is thrown.
      Returns:
      The generated schema bean, or null if a schema could not be generated for the class.
    • generate

      public JsonSchema<?> generate(Object o)
      Generates a schema bean from an object.

      The value can be a POJO or a Class/Type.

      Parameters:
      o - The value to infer a schema from. Must not be null, or an IllegalArgumentException is thrown.
      Returns:
      The generated schema bean, or null if a schema could not be generated for the value.
    • toBean

      public static JsonSchema<?> toBean(JsonMap schemaMap)
      Converts a generated schema map into a typed bean.

      Conversion uses a JSON roundtrip to ensure the swaps declared on JsonSchema are honored.

      Parameters:
      schemaMap - The generated schema map. Must not be null, or an IllegalArgumentException is thrown.
      Returns:
      The typed schema bean.