Class TypeRule

java.lang.Object
org.jsonschema2pojo.rules.TypeRule
All Implemented Interfaces:
Rule<com.sun.codemodel.JClassContainer,com.sun.codemodel.JType>

public class TypeRule extends Object implements Rule<com.sun.codemodel.JClassContainer,com.sun.codemodel.JType>
Applies the "type" schema rule.
See Also:
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    TypeRule(RuleFactory ruleFactory)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    com.sun.codemodel.JType
    apply(String nodeName, com.fasterxml.jackson.databind.JsonNode node, com.fasterxml.jackson.databind.JsonNode parent, com.sun.codemodel.JClassContainer jClassContainer, Schema schema)
    Applies this schema rule to take the required code generation steps.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • TypeRule

      protected TypeRule(RuleFactory ruleFactory)
  • Method Details

    • apply

      public com.sun.codemodel.JType apply(String nodeName, com.fasterxml.jackson.databind.JsonNode node, com.fasterxml.jackson.databind.JsonNode parent, com.sun.codemodel.JClassContainer jClassContainer, Schema schema)
      Applies this schema rule to take the required code generation steps.

      When applied, this rule reads the details of the given node to determine the appropriate Java type to return. This may be a newly generated type, it may be a primitive type or other type such as String or Object.

      JSON schema types and their Java type equivalent:

      • "type":"any" => Object
      • "type":"array" => Either Set or List, see ArrayRule
      • "type":"boolean" => boolean
      • "type":"integer" => int
      • "type":"null" => Object
      • "type":"number" => double
      • "type":"object" => Generated type (see ObjectRule)
      • "type":"string" => String (or alternative based on presence of "format", see FormatRule)
      Specified by:
      apply in interface Rule<com.sun.codemodel.JClassContainer,com.sun.codemodel.JType>
      Parameters:
      nodeName - the name of the node for which this "type" rule applies
      node - the node for which this "type" rule applies
      parent - the parent node
      jClassContainer - the package into which any newly generated type may be placed
      schema - the schema to which this schema rule (and the given node) belongs.
      Returns:
      the Java type which, after reading the details of the given schema node, most appropriately matches the "type" specified