how to generate non-string enum? #370
-
| 
         JavaBean: The Json Schema I expect for:  | 
  
Beta Was this translation helpful? Give feedback.
      
      
          Answered by
          
            CarstenWickner
          
      
      
        Jul 25, 2023 
      
    
    Replies: 1 comment 1 reply
-
| 
         Hi @EdwardJunyan, If you want special handling for a given type, a  configBuilder.forTypesInGeneral().withCustomDefinitionProvider((javaType, context) -> {
    if (!javaType.isInstanceOf(Test.NumberEnum.class)) {
        return null;
    }
    ObjectNode customNode = context.getGeneratorConfig().createObjectNode()
            .put(context.getKeyword(SchemaKeyword.TAG_TYPE), context.getKeyword(SchemaKeyword.TAG_TYPE_NUMBER));
    AttributeCollector collector = new AttributeCollector(context.getGeneratorConfig().getObjectMapper());
    List<Double> enumValues = Stream.of(Test.NumberEnum.values())
            .map(Test.NumberEnum::getValue)
            .collect(Collectors.toList());
    collector.setDefault(customNode, enumValues.get(0), context);
    collector.setEnum(customNode, enumValues, context);
    return new CustomDefinition(customNode);
}); | 
  
Beta Was this translation helpful? Give feedback.
                  
                    1 reply
                  
                
            
      Answer selected by
        EdwardJunyan
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
        
    
Hi @EdwardJunyan,
If you want special handling for a given type, a
CustomDefinitionProvideris the way to go.The below assumes that the
NumberEnumis notprivatebut visible from where the schema generator configuration is defined: