se.fortnox.reactivewizard.jaxrs.params.deserializing.EnumDeserializer Maven / Gradle / Ivy
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