All Downloads are FREE. Search and download functionalities are using the official Maven repository.

java-helidon.client.libraries.se.enumClass.mustache Maven / Gradle / Ivy

There is a newer version: 7.9.0
Show newest version
{{#jsonb}}
  @JsonbTypeSerializer({{datatypeWithEnum}}.Serializer.class)
  @JsonbTypeDeserializer({{datatypeWithEnum}}.Deserializer.class)
{{/jsonb}}
{{>additionalEnumTypeAnnotations}}public enum {{datatypeWithEnum}} {

    {{#allowableValues}}
    {{#enumVars}}{{name}}({{dataType}}.valueOf({{{value}}})){{^-last}}, {{/-last}}{{#-last}};{{/-last}}{{/enumVars}}
    {{/allowableValues}}

    {{dataType}} value;

    {{datatypeWithEnum}} ({{dataType}} v) {
        value = v;
    }

    public {{dataType}} value() {
        return value;
    }

    @Override
    public String toString() {
        return String.valueOf(value);
    }

    {{#jsonb}}
    public static final class Deserializer implements JsonbDeserializer<{{datatypeWithEnum}}> {
        @Override
        public {{datatypeWithEnum}} deserialize(JsonParser parser, DeserializationContext ctx, Type rtType) {
            for ({{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} b : {{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}}.values()) {
                if (String.valueOf(b.value).equals(parser.getString())) {
                    return b;
                }
            }
            {{#useNullForUnknownEnumValue}}return null;{{/useNullForUnknownEnumValue}}{{^useNullForUnknownEnumValue}}throw new IllegalArgumentException("Unexpected value '" + parser.getString() + "'");{{/useNullForUnknownEnumValue}}
        }
    }

    public static final class Serializer implements JsonbSerializer<{{datatypeWithEnum}}> {
        @Override
        public void serialize({{datatypeWithEnum}} obj, JsonGenerator generator, SerializationContext ctx) {
            generator.write(obj.value);
        }
    }
    {{/jsonb}}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy