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

com.mindee.parsing.common.ErrorDetailsDeserializer Maven / Gradle / Ivy

The newest version!
package com.mindee.parsing.common;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
import java.io.IOException;

/**
 * JSON deserializer for the error portion of the return.
 */
public class ErrorDetailsDeserializer extends StdDeserializer {

  public ErrorDetailsDeserializer(Class vc) {
    super(vc);
  }

  public ErrorDetailsDeserializer() {
    this(null);
  }

  @Override
  public ErrorDetails deserialize(
      JsonParser jsonParser,
      DeserializationContext deserializationContext
  ) throws IOException {

    JsonNode node = jsonParser.getCodec().readTree(jsonParser);
    String details;

    if (node.isObject()) {
      details = node.toString();
    } else if (node.isTextual()) {
      details = node.textValue();
    } else {
      throw new IllegalStateException("The JSON type is not handled.");
    }

    return new ErrorDetails(details);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy