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

net.sf.weixinmp.model.deserializer.GenericObjectDeserializer Maven / Gradle / Ivy

The newest version!
package net.sf.weixinmp.model.deserializer;

import java.lang.reflect.Type;
import java.util.Map.Entry;

import net.sf.weixinmp.model.GenericObject;

import com.google.gson.JsonArray;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import com.google.gson.JsonPrimitive;
/**
 * 仅仅处理一层的json
 * @author Alex
 *
 */
public class GenericObjectDeserializer implements JsonDeserializer{

	@Override
	public GenericObject deserialize(JsonElement json, Type type, JsonDeserializationContext ctx) throws JsonParseException {
		GenericObject ret=new GenericObject();
		JsonObject object=(JsonObject)json;
		for(Entry entry:object.entrySet()){
			if(entry.getValue() instanceof JsonPrimitive ) ret.put(entry.getKey(), entry.getValue().getAsString());
			else if(entry.getValue() instanceof JsonObject ) ret.put(entry.getKey(), entry.getValue().toString());
			else if(entry.getValue() instanceof JsonArray ) ret.put(entry.getKey(), entry.getValue().toString());
		}
		return ret;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy