Package org.jtester.json.decoder.object

Source Code of org.jtester.json.decoder.object.MapDecoder

package org.jtester.json.decoder.object;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import org.jtester.json.JSON;
import org.jtester.json.decoder.ObjectDecoder;
import org.jtester.json.helper.JSONMap;
import org.jtester.json.helper.JSONObject;

@SuppressWarnings({ "rawtypes", "unchecked" })
public class MapDecoder extends ObjectDecoder<Map> {

  public MapDecoder(Class clazz) {
    super(clazz);
  }

  public MapDecoder() {
    super(HashMap.class);
  }

  @Override
  protected void parseFromJSONMap(Map target, JSONMap jsonMap, Map<String, Object> references) {
    for (Iterator<JSONObject> iterator = jsonMap.keySet().iterator(); iterator.hasNext();) {
      JSONObject jsonkey = iterator.next();

      if (jsonkey.equals(JSONMap.JSON_ClazzFlag)) {
        continue;
      }
      Object key = JSON.toObject(jsonkey, references);
      JSONObject jsonvalue = jsonMap.get(jsonkey);
      Object value = JSON.toObject(jsonvalue, references);
      target.put(key, value);
    }
  }
}
TOP

Related Classes of org.jtester.json.decoder.object.MapDecoder

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.