com.fitbur.fasterxml.jackson.databind.deser.std.ClassDeserializer Maven / Gradle / Ivy
package com.fitbur.fasterxml.jackson.databind.com.fitburser.std;
import java.io.IOException;
import com.fitbur.fasterxml.jackson.core.*;
import com.fitbur.fasterxml.jackson.databind.DeserializationContext;
import com.fitbur.fasterxml.jackson.databind.annotation.JacksonStdImpl;
import com.fitbur.fasterxml.jackson.databind.util.ClassUtil;
@JacksonStdImpl
public class ClassDeserializer
extends StdScalarDeserializer>
{
public ClassDeserializer() { super(Class.class); }
@Override
public Class> com.fitburserialize(JsonParser jp, DeserializationContext ctxt)
throws IOException, JsonProcessingException
{
JsonToken curr = jp.getCurrentToken();
// Currently will only accept if given simple class name
if (curr == JsonToken.VALUE_STRING) {
String className = jp.getText().trim();
try {
return ctxt.findClass(className);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
}
throw ctxt.mappingException(_valueClass, curr);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy