Class JaxRsEnumRule

  • All Implemented Interfaces:
    org.jsonschema2pojo.rules.Rule<com.sun.codemodel.JClassContainer,​com.sun.codemodel.JType>

    public class JaxRsEnumRule
    extends Object
    implements org.jsonschema2pojo.rules.Rule<com.sun.codemodel.JClassContainer,​com.sun.codemodel.JType>
    Author:
    eric.wittmann@gmail.com
    • Constructor Detail

      • JaxRsEnumRule

        protected JaxRsEnumRule​(org.jsonschema2pojo.rules.RuleFactory ruleFactory)
    • Method Detail

      • 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 container,
                                             org.jsonschema2pojo.Schema schema)
        Applies this schema rule to take the required code generation steps.

        A Java Enum is created, with constants for each of the enum values present in the schema. The enum name is derived from the nodeName, and the enum type itself is created as an inner class of the owning type. In the rare case that no owning type exists (the enum is the root of the schema), then the enum becomes a public class in its own right.

        The actual JSON value for each enum constant is held in a property called "value" in the generated type. A static factory method fromValue(String) is added to the generated enum, and the methods are annotated to allow Jackson to marshal/unmarshal values correctly.

        Specified by:
        apply in interface org.jsonschema2pojo.rules.Rule<com.sun.codemodel.JClassContainer,​com.sun.codemodel.JType>
        Parameters:
        nodeName - the name of the property which is an "enum"
        node - the enum node
        container - the class container (class or package) to which this enum should be added
        Returns:
        the newly generated Java type that was created to represent the given enum
        See Also:
        Rule.apply(java.lang.String, com.fasterxml.jackson.databind.JsonNode, com.fasterxml.jackson.databind.JsonNode, java.lang.Object, org.jsonschema2pojo.Schema)
      • getConstantName

        protected String getConstantName​(String nodeName,
                                         String customName)