All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.jd.blockchain.utils.serialize.json.RuntimeDeserializer Maven / Gradle / Ivy

There is a newer version: 1.4.0.RELEASE
Show newest version
package com.jd.blockchain.utils.serialize.json;

import java.lang.reflect.Type;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import com.alibaba.fastjson.parser.DefaultJSONParser;
import com.alibaba.fastjson.parser.JSONToken;
import com.alibaba.fastjson.parser.deserializer.ObjectDeserializer;

public class RuntimeDeserializer implements ObjectDeserializer {
	
	private Map, Class> typeMap = new ConcurrentHashMap, Class>();
	
	synchronized void addTypeMap(Class fromClazz, Class toClazz){
		typeMap.put(fromClazz, toClazz);
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public  T deserialze(DefaultJSONParser parser, Type type, Object fieldName) {
		if (type instanceof Class) {
			Class toClazz = typeMap.get((Class) type);
			if (toClazz != null) {
				return (T) parser.parseObject(toClazz);
			}
		}
		return (T) parser.parse(fieldName);
	}

	@Override
	public int getFastMatchToken() {
		return JSONToken.LBRACE;
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy