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

se.fortnox.reactivewizard.jaxrs.params.deserializing.EnumDeserializer Maven / Gradle / Ivy

There is a newer version: 24.6.0
Show newest version
package se.fortnox.reactivewizard.jaxrs.params.deserializing;

/**
 * Deserializes enums.
 */
public class EnumDeserializer> implements Deserializer {
    private final Class paramType;

    public EnumDeserializer(Class paramType) {
        this.paramType = paramType;
    }

    @Override
    public T deserialize(String value) throws DeserializerException {
        if (value == null || value.isEmpty()) {
            return null;
        }
        try {
            return Enum.valueOf(paramType, value);
        } catch (Exception parseException) {
            try {
                return Enum.valueOf(paramType, value.toUpperCase());
            } catch (Exception e) {
                throw new DeserializerException("invalid.enum");
            }

        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy