All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.dropbox.client2.jsonextract.JsonExtractionException Maven / Gradle / Ivy

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 - 2025 Weber Informatics LLC | Privacy Policy