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

ca.fuzzlesoft.JsonParseException Maven / Gradle / Ivy

package ca.fuzzlesoft;

import ca.fuzzlesoft.JsonParse.State;

import java.util.List;
import java.util.Stack;

/**
 * @author mitch
 * @since 30/12/15
 */
public class JsonParseException extends RuntimeException {

    private final String message;

    public JsonParseException(String message) {
        this.message = message;
    }

    public JsonParseException(Stack stateStack, String message) {
        String jsonTrace = "";
        for (int i = 0; i < stateStack.size(); i++) {
            String name = stateStack.get(i).propertyName;
            if (name == null) {
                // Fill in array index
                List list = (List) stateStack.get(i).container;
                name = String.format("[%d]", list.size());
            }
            jsonTrace += name + (i != stateStack.size() - 1 ? "." : "");
        }

        jsonTrace = jsonTrace.equals("") ? "" : "." + jsonTrace;

        this.message = jsonTrace + ": " + message;
    }

    @Override
    public String getMessage() {
        return message;
    }
}