Code example for JsonArray

0
 
public class MapAdapter<K, V> implements JsonSerializer<Map<K, V>>, JsonDeserializer<Map<K, V>> {
 
    @Override 
    public JsonElement serialize(Map<K, V> m, Type typeOfT, JsonSerializationContext context) {
        JsonArray rv = new JsonArray();
        for (K k : m.keySet()) {
            JsonObject kv = new JsonObject();
            kv.add        ("k"     , context.serialize(k));
            kv.addProperty("ktype" , k==null?null:k.getClass().getName());
            kv.add        ("v"     , context.serialize(m.get(k)));
            kv.addProperty("vtype" , m.get(k)==null?null:m.get(k).getClass().getName());
            rv.add(kv);
        } 
        return rv;
    } 
 
    @Override 
    public Map<K, V> deserialize(JsonElement _json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
        JsonArray json = (JsonArray) _json;
Contextual code suggestions in your IDE  Get Codota for Java