List of usage examples for com.fasterxml.jackson.core JsonLocation getColumnNr
public int getColumnNr()
From source file:com.reprezen.swagedit.model.NodeDeserializer.java
private Location createLocation(JsonLocation json) { return new Location(json.getLineNr() - 1, json.getColumnNr() - 1); }
From source file:org.emfjson.jackson.errors.JSONException.java
public JSONException(Exception e, JsonLocation location) { super(e);/*from w w w . ja va 2s. c o m*/ this.location = location.toString(); this.line = location.getLineNr(); this.column = location.getColumnNr(); }
From source file:org.emfjson.jackson.errors.JSONException.java
public JSONException(String message, JsonLocation location) { super(message); this.location = location.toString(); this.line = location.getLineNr(); this.column = location.getColumnNr(); }
From source file:org.seedstack.seed.core.internal.data.DataManagerImpl.java
private void throwParsingError(JsonLocation jsonLocation, String message) { throw SeedException.createNew(DataErrorCode.FAILED_TO_PARSE_DATA_STREAM).put("parsingError", message) .put("line", jsonLocation.getLineNr()).put("col", jsonLocation.getColumnNr()) .put("offset", jsonLocation.getCharOffset()); }
From source file:com.github.jknack.handlebars.server.HbsServlet.java
/** * Deal with a {@link HandlebarsException}. * * @param ex The handlebars exception./* www . j av a2 s. c o m*/ * @param request The http request. * @param response The http response. * @throws IOException If something goes wrong. */ private void jsonError(final JsonParseException ex, final HttpServletRequest request, final HttpServletResponse response) throws IOException { Map<String, Object> root = new HashMap<String, Object>(); Map<String, Object> error = new HashMap<String, Object>(); String filename = jsonFilename(request); JsonLocation location = ex.getLocation(); String reason = ex.getMessage(); int atIdx = reason.lastIndexOf(" at "); if (atIdx > 0) { reason = reason.substring(0, atIdx); } error.put("filename", filename); error.put("line", location.getLineNr()); error.put("column", location.getColumnNr()); error.put("reason", reason); error.put("type", "JSON error"); String json = read(filename); StringBuilder evidence = new StringBuilder(); int i = (int) location.getCharOffset(); int nl = 0; while (i >= 0 && nl < 2) { char ch = json.charAt(i); if (ch == '\n') { nl++; } evidence.insert(0, ch); i--; } i = (int) location.getCharOffset() + 1; nl = 0; while (i < json.length() && nl < 2) { char ch = json.charAt(i); if (ch == '\n') { nl++; } evidence.append(ch); i++; } error.put("evidence", evidence); root.put("error", error); int firstLine = Math.max(1, ex.getLocation().getLineNr() - 1); fancyError(root, firstLine, "JScript", response); }
From source file:com.quinsoft.zeidon.standardoe.ActivateOisFromJsonStream.java
public List<View> read() { try {//from w ww . ja va 2s. c o m JsonFactory jsonFactory = new JsonFactory(); jp = jsonFactory.createParser(stream); jp.configure(JsonParser.Feature.AUTO_CLOSE_SOURCE, false); // Read the START_OBJECT JsonToken token = jp.nextToken(); if (token != JsonToken.START_OBJECT) throw new ZeidonException("OI JSON stream doesn't start with object."); token = jp.nextToken(); if (token != JsonToken.FIELD_NAME) throw new ZeidonException("OI JSON missing OI field name."); String fieldName = jp.getCurrentName(); if (fieldName.equals(".meta")) { readFileMeta(); JsonReader reader = getReaderForVersion(); reader.process(); } else { if (StringUtils.equalsIgnoreCase(fieldName, "version")) { token = jp.nextToken(); // Move to value. version = jp.getValueAsString(); token = jp.nextToken(); // Move to next field name. assert token == JsonToken.FIELD_NAME; fieldName = jp.getCurrentName(); } else if (StringUtils.isBlank(options.getVersion())) { throw new ZeidonException("First field must be version"); } totalRootCount = null; if (StringUtils.equalsIgnoreCase(fieldName, "totalRootCount")) { token = jp.nextToken(); // Move to value. totalRootCount = jp.getValueAsInt(); token = jp.nextToken(); // Move to next field name. assert token == JsonToken.FIELD_NAME; fieldName = jp.getCurrentName(); } if (lodDef == null) throw new ZeidonException("JSON stream appears to start with the root entity name (%s)" + " but the LodDef has not been specified.", fieldName); String rootName = lodDef.getRoot().getName(); if (!fieldName.equalsIgnoreCase(rootName)) throw new ZeidonException("The first field in the JSON stream must be the root entity name" + " (%s) or '.meta' but was %s.", rootName, fieldName); view = task.activateEmptyObjectInstance(lodDef); returnList.add(view); if (totalRootCount != null) view.setTotalRootCount(totalRootCount); JsonReader reader = getSimpleReaderForVersion(); reader.process(); } jp.close(); } catch (Exception e) { ZeidonException ze = ZeidonException.wrapException(e); JsonLocation loc = jp.getCurrentLocation(); JsonToken token = jp.getCurrentToken(); ze.appendMessage("Position line=%d col=%d, token=%s", loc.getLineNr(), loc.getColumnNr(), token == null ? "No Token" : token.name()); throw ze; } return returnList; }
From source file:org.eclipse.rdf4j.rio.rdfjson.RDFJSONParser.java
/** * Creates a literal, using the current value, language, and datatype, and additionally using the given * {@link JsonLocation} to provide information about the line and column numbers in the event of a * warning, error or exception being generated by the creation of the literal. * //from w w w .j a va 2 s . c o m * @param label * the literal's lexical label * @param language * the literal's language tag. Can be null. * @param datatype * the literal's datatype. Can be null. * @param currentLocation * the current JsonLocation. May not be null. * @return the created {@link Literal} object. * @throws RDFParseException */ protected Literal createLiteral(String label, String language, IRI datatype, JsonLocation currentLocation) throws RDFParseException { return createLiteral(label, language, datatype, currentLocation.getLineNr(), currentLocation.getColumnNr()); }
From source file:org.eclipse.rdf4j.rio.rdfjson.RDFJSONParser.java
protected void reportError(String msg, Throwable e, JsonLocation location, RioSetting<Boolean> setting) throws RDFParseException { reportError(msg, location.getLineNr(), location.getColumnNr(), setting); }
From source file:org.eclipse.rdf4j.rio.rdfjson.RDFJSONParser.java
protected void reportError(String msg, JsonLocation location, RioSetting<Boolean> setting) throws RDFParseException { reportError(msg, location.getLineNr(), location.getColumnNr(), setting); }
From source file:org.eclipse.rdf4j.rio.rdfjson.RDFJSONParser.java
protected void reportFatalError(String msg, Throwable e, JsonLocation location) throws RDFParseException { reportFatalError(msg, location.getLineNr(), location.getColumnNr()); }