top.jfunc.json.impl.JSONObject Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of Json-jackson Show documentation
Show all versions of Json-jackson Show documentation
common json interface implements by jackson
The newest version!
package top.jfunc.json.impl;
import top.jfunc.json.Json;
import top.jfunc.json.JsonArray;
import top.jfunc.json.JsonException;
import top.jfunc.json.JsonObject;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author xiongshiyan at 2018/6/10
*/
public class JSONObject extends BaseMapJSONObject {
private static final ObjectMapper objectMapper = new ObjectMapper();
public JSONObject(Map map){
super(map);
}
public JSONObject(){
super();
}
public JSONObject(String jsonString){
super(jsonString);
}
@Override
protected Map str2Map(String jsonString) {
try {
return objectMapper.readValue(jsonString , Map.class);
} catch (IOException e) {
throw new JsonException(e);
}
}
@Override
public JsonObject getJsonObject(String key) {
assertKey(key);
//这里不能使用getJSONObject,因为每一种Json实现不一样,给出的JsonObject类型是不一致的。
//这里就是各种JsonObject不能混用的原因
Object temp = this.map.get(key);
Object t = checkNullValue(key, temp);
if(t instanceof Map){
return new JSONObject((Map) t);
}
return (JsonObject) t;
}
@Override
public JsonArray getJsonArray(String key) {
assertKey(key);
//这里不能使用getJSONObject,因为每一种Json实现不一样,给出的JsonObject类型是不一致的。
//这里就是各种JsonObject不能混用的原因
Object temp = this.map.get(key);
Object t = checkNullValue(key, temp);
if(t instanceof List){
return new JSONArray((List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy