javajacksonjooqjooq-codegen

How to make Jooq Codegen generated Enums work with Deserialization Libraries (like Jackson)


The Jooq Codegenerator creates Enums (when it can) for database columns that allow it to.

It would be helpful to let the Enums be Deserializable by Libraries like Jackson, which is currently not the case.

My Use-Case:

What is considered the Best Practice for this Use-Case?


Example of a Jooq Codegen created Enum:

/**
 * This class is generated by jOOQ.
 */
@SuppressWarnings({ "all", "unchecked", "rawtypes", "this-escape" })
public enum MatchingslotStatus implements EnumType {

    AVAILABLE("AVAILABLE"),

    SEARCHING("SEARCHING"),

    ANSWER_WAITING("ANSWER_WAITING"),

    ANSWER_EXPECTED("ANSWER_EXPECTED"),

    FINISHED("FINISHED");

    private final String literal;

    private MatchingslotStatus(String literal) {
        this.literal = literal;
    }

    @Override
    public Catalog getCatalog() {
        return null;
    }

    @Override
    public Schema getSchema() {
        return null;
    }

    @Override
    public String getName() {
        return null;
    }

    @Override
    public String getLiteral() {
        return literal;
    }

    /**
     * Lookup a value of this EnumType by its literal. Returns
     * <code>null</code>, if no such value could be found, see {@link
     * EnumType#lookupLiteral(Class, String)}.
     */
    public static MatchingslotStatus lookupLiteral(String literal) {
        return EnumType.lookupLiteral(MatchingslotStatus.class, literal);
    }
}

Solution

  • The problem in the question could not be reproduced (anymore).

    When testing the problem, jackson correctly deserializes json to the jooq generated enum:

    public class Main {
    
        public static void main(String[] args) throws JsonProcessingException {
    
            String jsonStr = "{\"status\": \"GENDER\" }";
    
            MyTest test = new ObjectMapper().readValue(jsonStr, MyTest.class);
    
            System.out.println(test);
        }
    
        public static final class MyTest {
    
            MatchingslotfilterFiltertype status;
    
            public MatchingslotfilterFiltertype getStatus() {
                return status;
            }
    
            public void setStatus(MatchingslotfilterFiltertype status) {
                this.status = status;
            }
        }
    }