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

hirezapi.json.deserializer.BooleanTextDeserializer Maven / Gradle / Ivy

The newest version!
package hirezapi.json.deserializer;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;

import java.io.IOException;

public class BooleanTextDeserializer extends JsonDeserializer {
  @Override
  public Boolean deserialize(JsonParser p, DeserializationContext ctxt)
        throws IOException, JsonProcessingException {
    try {
      return p.getBooleanValue();
    } catch (IOException ignore) {
      String b = p.getText();
      if (b.equalsIgnoreCase("y")) {
        return true;
      } else if (b.equalsIgnoreCase("n")) {
        return false;
      }
      return false;
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy