com.dropbox.client2.jsonextract.JsonExtractionException Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of dropbox-java-sdk Show documentation
Show all versions of dropbox-java-sdk Show documentation
The Dropbox API for Java is a Dropbox supported client library for accessing the
JSON+REST interface to Dropbox. It supports OAuth proxied authentication. It is
designed to be simple and easy to use, as well as instructional in case you want
to write your own. It is MIT licensed.
The newest version!
package com.dropbox.client2.jsonextract;
import static org.json.simple.JSONValue.toJSONString;
import java.util.List;
import java.util.Map;
public final class JsonExtractionException extends Exception {
private static final long serialVersionUID = -5744582005002105505L;
public JsonExtractionException(String path, String message, Object value) {
super((path == null ? "" : path + ": ") + message +
(value == null ? "" : ": " + summarizeValue(value)));
}
private static String summarizeValue(Object value) {
if (value instanceof java.util.Map) {
StringBuilder buf = new StringBuilder();
@SuppressWarnings("unchecked")
Map map = (Map) value;
buf.append("{");
String sep = "";
for (Map.Entry entry : map.entrySet()) {
buf.append(sep); sep = ", ";
buf.append(toJSONString(entry.getKey()));
buf.append(" = ");
buf.append("...");
}
buf.append("}");
return buf.toString();
}
else if (value instanceof java.util.List) {
List> list = (List>) value;
if (list.isEmpty()) {
return "[]";
} else if (list.size() == 1) {
return "[" + summarizeValue(list.get(0)) + "]";
} else {
return "[" + summarizeValue(list.get(0)) + ", ...] (" + list.size() + " elements)";
}
}
else {
return toJSONString(value);
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy