
com.qiniu.service.line.JsonObjParser Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of qsuits Show documentation
Show all versions of qsuits Show documentation
qiniu-suits is a efficient tools for qiniu api implemented by java8.
package com.qiniu.service.line;
import com.google.gson.JsonNull;
import com.google.gson.JsonObject;
import com.qiniu.service.interfaces.ILineParser;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
public class JsonObjParser implements ILineParser {
private Map indexMap;
private boolean forceParse;
public JsonObjParser(Map indexMap, boolean forceParse) throws IOException {
if (indexMap == null || indexMap.size() == 0) throw new IOException("there are no indexMap be set.");
this.indexMap = indexMap;
this.forceParse = forceParse;
}
public Map getItemMap(JsonObject json) throws IOException {
Map itemMap = new HashMap<>();
String mapKey;
for (String key : json.keySet()) {
mapKey = indexMap.get(key);
if (mapKey != null) {
if (json.get(key) instanceof JsonNull) itemMap.put(mapKey, null);
else itemMap.put(mapKey, json.get(key).getAsString());
}
}
if (!forceParse && itemMap.size() < indexMap.size())
throw new IOException("no enough indexes in line. The parameter indexes may have incorrect order or name.");
return itemMap;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy