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

io.blitz.gson.MapDeserializer Maven / Gradle / Ivy

The newest version!
package io.blitz.gson;

import java.util.Map;
import java.util.HashMap;
import java.lang.reflect.Type;
import com.google.gson.JsonObject;
import com.google.gson.JsonElement;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonParseException;
import com.google.gson.JsonDeserializationContext;

/** 
 * @author ghermeto
 */
public class MapDeserializer extends DeserializerHelper
    implements JsonDeserializer> {

    /**
     * 
     * @param element
     * @param typeOfT
     * @param context
     * @return
     * @throws JsonParseException 
     */
    public Map deserialize(JsonElement element, Type typeOfT, 
            JsonDeserializationContext context) throws JsonParseException {
        if (element.isJsonNull()) {
            return null;
        } 
        JsonObject json = element.getAsJsonObject();
        Map result = new HashMap();
        for (Map.Entry entry : json.entrySet()) {
            JsonElement jsonValue = entry.getValue();
            result.put(entry.getKey(), getValue(jsonValue, context));
        }
        return result;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy