com.mindee.parsing.common.ErrorDetailsDeserializer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mindee-api-java Show documentation
Show all versions of mindee-api-java Show documentation
Java Library to call Mindee's Off-The-Shelf and Custom APIs
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);
}
}