Java Code Examples for com.fasterxml.jackson.core.JsonLocation#getLineNr()

The following examples show how to use com.fasterxml.jackson.core.JsonLocation#getLineNr() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BaseJsonProcessor.java    From Bats with Apache License 2.0 5 votes vote down vote up
@Override
public String toString() {
  JsonLocation location = parser.getCurrentLocation();
  return getClass().getSimpleName() + "[Line=" + location.getLineNr()
      + ", Column=" + (location.getColumnNr() + 1)
      + ", Field=" + getCurrentField()
      + "]";
}
 
Example 2
Source File: JSONMatrixParser.java    From sailfish-core with Apache License 2.0 5 votes vote down vote up
@Override
public CustomValue getNullValue(DeserializationContext ctxt){
    JsonLocation currentLocation = ctxt.getParser().getCurrentLocation();
    int lineNr = currentLocation.getLineNr();
    int column = currentLocation.getColumnNr();
    return new NullValue(lineNr, column);
}
 
Example 3
Source File: JsonXContentParser.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public XContentLocation getTokenLocation() {
    JsonLocation loc = parser.getTokenLocation();
    if (loc == null) {
        return null;
    }
    return new XContentLocation(loc.getLineNr(), loc.getColumnNr());
}
 
Example 4
Source File: ParseError.java    From json-schema-validator-demo with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static JsonNode build(final JsonProcessingException e,
    final boolean crlf)
{
    final JsonLocation location = e.getLocation();
    final ObjectNode ret = JsonNodeFactory.instance.objectNode();

    /*
     * Unfortunately, for some reason, Jackson botches the column number in
     * its JsonPosition -- I cannot figure out why exactly. However, it does
     * have a correct offset into the buffer.
     *
     * The problem is that if the input has CR/LF line terminators, its
     * offset will be "off" by the number of lines minus 1 with regards to
     * what JavaScript sees as positions in text areas. Make the necessary
     * adjustments so that the caret jumps at the correct position in this
     * case.
     */
    final int lineNr = location.getLineNr();
    int offset = (int) location.getCharOffset();
    if (crlf)
        offset = offset - lineNr + 1;
    ret.put(LINE, lineNr);
    ret.put(OFFSET, offset);

    // Finally, put the message
    ret.put(MESSAGE, e.getOriginalMessage());
    return ret;
}
 
Example 5
Source File: JsonXContentParser.java    From crate with Apache License 2.0 5 votes vote down vote up
@Override
public XContentLocation getTokenLocation() {
    JsonLocation loc = parser.getTokenLocation();
    if (loc == null) {
        return null;
    }
    return new XContentLocation(loc.getLineNr(), loc.getColumnNr());
}
 
Example 6
Source File: JSONMatrixParser.java    From sailfish-core with Apache License 2.0 4 votes vote down vote up
@Override
public Object deserializeKey(String key, DeserializationContext ctxt) throws IOException {
    JsonLocation tokenLocation = ctxt.getParser().getCurrentLocation();
    return new KeyValue(tokenLocation.getLineNr(), tokenLocation.getColumnNr(), key);
}
 
Example 7
Source File: NodeDeserializer.java    From KaiZen-OpenAPI-Editor with Eclipse Public License 1.0 4 votes vote down vote up
private Location createLocation(JsonLocation json) {
    return new Location(json.getLineNr() - 1, json.getColumnNr() - 1);
}
 
Example 8
Source File: JsonProcessingExceptionMapper.java    From ameba with MIT License 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public Response toResponse(JsonProcessingException exception) {
    Throwable throwable = exception;
    while (throwable != null) {
        if (throwable instanceof PersistenceException) {
            return exceptionMappers.get().findMapping(throwable).toResponse(throwable);
        }
        throwable = throwable.getCause();
    }

    logger.debug("Json Processing error", exception);
    String message = exception.getOriginalMessage();
    String desc = null;
    String source = null;
    if (mode.isDev()) {
        desc = IOUtils.getStackTrace(exception);
        JsonLocation location = exception.getLocation();
        if (location != null) {
            source = "line: " + location.getLineNr() +
                    ", column: " + location.getColumnNr();
        } else {
            source = exception.getStackTrace()[0].toString();
        }
    }

    ErrorMessage errorMessage = ErrorMessage.fromStatus(Response.Status.BAD_REQUEST.getStatusCode());
    errorMessage.setThrowable(exception);
    errorMessage.setCode(Hashing.murmur3_32().hashUnencodedChars(exception.getClass().getName()).toString());

    errorMessage.addError(new Result.Error(
            errorMessage.getCode(),
            message != null ? message : exception.getMessage(),
            desc,
            source
    ));

    return Response.status(errorMessage.getStatus())
            .entity(errorMessage)
            .type(ExceptionMapperUtils.getResponseType())
            .build();
}