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

main.java.com.nutanix.dp1.vmm.deserializers.VmmCaseInsensitiveEnumDeserializer Maven / Gradle / Ivy

package com.nutanix.dp1.vmm.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 VmmCaseInsensitiveEnumDeserializer> extends StdDeserializer {

  private final Class tClass;

  protected VmmCaseInsensitiveEnumDeserializer(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());
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy