panda.cast.castor.AnyJsonCastor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of panda-core Show documentation
Show all versions of panda-core Show documentation
Panda Core is the core module of Panda Framework, it contains commonly used utility classes similar to apache-commons.
package panda.cast.castor;
import java.io.InputStream;
import java.io.Reader;
import java.lang.reflect.Type;
import panda.bind.json.Jsons;
import panda.lang.Charsets;
/**
*
* @param target type
*/
public abstract class AnyJsonCastor extends AnyObjectCastor {
public AnyJsonCastor(Type toType) {
super(toType);
}
@Override
protected Object prepare(Object value) {
if (value instanceof CharSequence) {
return Jsons.fromJson((CharSequence)value, toType);
}
if (value instanceof Reader) {
return Jsons.fromJson((Reader)value, toType);
}
if (value instanceof InputStream) {
return Jsons.fromJson((InputStream)value, Charsets.UTF_8, toType);
}
return value;
}
}