Search in sources :

Example 1 with IonParser

use of com.fasterxml.jackson.dataformat.ion.IonParser in project jackson-dataformats-binary by FasterXML.

the class IonValueDeserializer method deserialize.

@Override
public IonValue deserialize(JsonParser jp, DeserializationContext ctxt) throws JacksonException {
    Object embeddedObject = jp.getEmbeddedObject();
    if (embeddedObject instanceof IonValue) {
        return (IonValue) embeddedObject;
    }
    // We rely on the IonParser's IonSystem to wrap supported types into an IonValue
    if (!(jp instanceof IonParser)) {
        throw DatabindException.from(jp, "Unsupported parser for deserializing " + embeddedObject.getClass().getCanonicalName() + " into IonValue");
    }
    IonSystem ionSystem = ((IonParser) jp).getIonSystem();
    if (embeddedObject instanceof Timestamp) {
        return ionSystem.newTimestamp((Timestamp) embeddedObject);
    }
    if (embeddedObject instanceof byte[]) {
        // The parser provides no distinction between BLOB and CLOB, deserializing to a BLOB is the safest choice.
        return ionSystem.newBlob((byte[]) embeddedObject);
    }
    throw DatabindException.from(jp, "Cannot deserialize embedded object type " + embeddedObject.getClass().getCanonicalName() + " into IonValue");
}
Also used : IonValue(com.amazon.ion.IonValue) IonSystem(com.amazon.ion.IonSystem) IonParser(com.fasterxml.jackson.dataformat.ion.IonParser) Timestamp(com.amazon.ion.Timestamp)

Aggregations

IonSystem (com.amazon.ion.IonSystem)1 IonValue (com.amazon.ion.IonValue)1 Timestamp (com.amazon.ion.Timestamp)1 IonParser (com.fasterxml.jackson.dataformat.ion.IonParser)1