com.fasterxml.jackson.databind.deser.std.ClassDeserializer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ehcache Show documentation
Show all versions of ehcache Show documentation
Ehcache is an open source, standards-based cache used to boost performance,
offload the database and simplify scalability. Ehcache is robust, proven and full-featured and
this has made it the most widely-used Java-based cache.
package com.fasterxml.jackson.databind.deser.std;
import java.io.IOException;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.annotation.JacksonStdImpl;
import com.fasterxml.jackson.databind.util.ClassUtil;
@JacksonStdImpl
public class ClassDeserializer
extends StdScalarDeserializer>
{
private static final long serialVersionUID = 1L;
public final static ClassDeserializer instance = new ClassDeserializer();
public ClassDeserializer() { super(Class.class); }
@Override
public Class> deserialize(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);
}
}