com.nutanix.dp1.dat.deserializers.DatCaseInsensitiveEnumDeserializer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of dataprotection-java-client Show documentation
Show all versions of dataprotection-java-client Show documentation
Business Continuity with full spectrum of Disaster Recovery and Backup solution. Spanning across Single PC, Cross AZ, MultiSite. Configuration of Recovery points, Protection policies, Recovery Plans. Execution and monitoring of back up and recovery orchestrations on OnPrem as well as Cloud.
The newest version!
package com.nutanix.dp1.dat.deserializers;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.ObjectCodec;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
import lombok.extern.slf4j.Slf4j;
import java.io.IOException;
@Slf4j
public abstract class DatCaseInsensitiveEnumDeserializer> extends StdDeserializer {
private final Class tClass;
protected DatCaseInsensitiveEnumDeserializer(Class tClass) {
super(tClass);
this.tClass = tClass;
}
@Override
public T deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
ObjectCodec codec = jsonParser.getCodec();
JsonNode node = codec.readTree(jsonParser);
String value = node.textValue();
return Enum.valueOf(tClass, value.toUpperCase());
}
}