com.fasterxml.jackson.core.JsonLocation

Here are the examples of the java api class com.fasterxml.jackson.core.JsonLocation taken from open source projects.

1. OpenRtbJsonExtComplexReader#readRepeated()

Project: openrtb
File: OpenRtbJsonExtComplexReader.java
@SuppressWarnings("unchecked")
private void readRepeated(EB msg, JsonParser par) throws IOException {
    par.nextToken();
    JsonToken tokLast = par.getCurrentToken();
    JsonLocation locLast = par.getCurrentLocation();
    for (startArray(par); endArray(par); par.nextToken()) {
        boolean objRead = false;
        XB ext = (XB) key.getMessageDefaultInstance().toBuilder();
        for (startObject(par); endObject(par); par.nextToken()) {
            read(ext, par);
            JsonToken tokNew = par.getCurrentToken();
            JsonLocation locNew = par.getCurrentLocation();
            if (tokNew != tokLast || !locNew.equals(locLast)) {
                objRead = true;
            }
            tokLast = tokNew;
            locLast = locNew;
        }
        if (objRead) {
            msg.addExtension(key, ext.build());
        }
    }
}

2. OpenRtbJsonExtComplexReader#readSingle()

Project: openrtb
File: OpenRtbJsonExtComplexReader.java
@SuppressWarnings("unchecked")
private void readSingle(EB msg, JsonParser par, XB ext) throws IOException {
    if (isJsonObject) {
        startObject(par);
    }
    boolean extRead = false;
    JsonToken tokLast = par.getCurrentToken();
    JsonLocation locLast = par.getCurrentLocation();
    while (endObject(par)) {
        read(ext, par);
        if (par.getCurrentToken() != tokLast || !par.getCurrentLocation().equals(locLast)) {
            extRead = true;
            par.nextToken();
            tokLast = par.getCurrentToken();
            locLast = par.getCurrentLocation();
        } else {
            break;
        }
    }
    if (extRead) {
        msg.setExtension(key, ext.build());
    }
    if (isJsonObject) {
        par.nextToken();
    }
}

3. AbstractOpenRtbJsonReader#readExtensions()

Project: openrtb
File: AbstractOpenRtbJsonReader.java
/**
   * Read any extensions that may exist in a message.
   *
   * @param msg Builder of a message that may contain extensions
   * @param par The JSON parser, positioned at the "ext" field
   * @param <EB> Type of message builder being constructed
   * @throws IOException any parsing error
   */
protected final <EB extends ExtendableBuilder<?, EB>> void readExtensions(EB msg, JsonParser par) throws IOException {
    @SuppressWarnings("unchecked") Set<OpenRtbJsonExtReader<EB>> extReaders = factory.getReaders((Class<EB>) msg.getClass());
    if (extReaders.isEmpty()) {
        par.skipChildren();
        return;
    }
    startObject(par);
    JsonToken tokLast = par.getCurrentToken();
    JsonLocation locLast = par.getCurrentLocation();
    while (true) {
        boolean extRead = false;
        for (OpenRtbJsonExtReader<EB> extReader : extReaders) {
            if (extReader.filter(par)) {
                extReader.read(msg, par);
                JsonToken tokNew = par.getCurrentToken();
                JsonLocation locNew = par.getCurrentLocation();
                boolean advanced = tokNew != tokLast || !locNew.equals(locLast);
                extRead |= advanced;
                if (!endObject(par)) {
                    return;
                } else if (advanced && par.getCurrentToken() != JsonToken.FIELD_NAME) {
                    tokLast = par.nextToken();
                    locLast = par.getCurrentLocation();
                } else {
                    tokLast = tokNew;
                    locLast = locNew;
                }
            }
        }
        if (!endObject(par)) {
            // Can't rely on this exit condition inside the for loop because no readers may filter.
            return;
        }
        if (!extRead) {
            // No field was consumed by any reader, so we need to skip the field to make progress.
            if (logger.isDebugEnabled()) {
                logger.debug("Extension field not consumed by any reader, skipping: {} @{}:{}", par.getCurrentName(), locLast.getLineNr(), locLast.getCharOffset());
            }
            par.nextToken();
            par.skipChildren();
            tokLast = par.nextToken();
            locLast = par.getCurrentLocation();
        }
    // Else loop, try all readers again
    }
}

4. JsonParserReader#getLocationString()

Project: immutables
File: JsonParserReader.java
private String getLocationString() {
    JsonLocation l = parser.getCurrentLocation();
    List<String> parts = new ArrayList<>(4);
    parts.add("line: " + l.getLineNr());
    parts.add("column: " + l.getColumnNr());
    if (l.getByteOffset() >= 0) {
        parts.add("byte offset: " + l.getByteOffset());
    }
    return parts.toString();
}

5. JsonParseExceptionMapper#toResponse()

Project: heroic
File: JsonParseExceptionMapper.java
@Override
public Response toResponse(JsonParseException e) {
    final JsonLocation l = e.getLocation();
    return Response.status(Response.Status.BAD_REQUEST).entity(new JsonParseErrorMessage(e.getOriginalMessage(), Response.Status.BAD_REQUEST, l.getLineNr(), l.getColumnNr())).type(MediaType.APPLICATION_JSON).build();
}

6. JsonXContentParser#getTokenLocation()

Project: elasticsearch
File: JsonXContentParser.java
@Override
public XContentLocation getTokenLocation() {
    JsonLocation loc = parser.getTokenLocation();
    if (loc == null) {
        return null;
    }
    return new XContentLocation(loc.getLineNr(), loc.getColumnNr());
}

7. JsonXContentParser#getTokenLocation()

Project: elassandra
File: JsonXContentParser.java
@Override
public XContentLocation getTokenLocation() {
    JsonLocation loc = parser.getTokenLocation();
    if (loc == null) {
        return null;
    }
    return new XContentLocation(loc.getLineNr(), loc.getColumnNr());
}

8. DbxEntry#_read()

Project: dropbox-sdk-java
File: DbxEntry.java
/**
     * @return
 *     {@code null} if the entry is an 'is_deleted' entry.
     */
private static <C> /*@Nullable*/
WithChildrenC<C> _read(JsonParser parser, /*@Nullable*/
Collector<DbxEntry, ? extends C> collector, boolean allowDeleted) throws IOException, JsonReadException {
    JsonLocation top = JsonReader.expectObjectStart(parser);
    String size = null;
    long bytes = -1;
    String path = null;
    Boolean is_dir = null;
    Boolean is_deleted = null;
    String rev = null;
    Boolean thumb_exists = null;
    String icon = null;
    Date modified = null;
    Date client_mtime = null;
    String hash = null;
    C contents = null;
    File.PhotoInfo photo_info = null;
    File.VideoInfo video_info = null;
    while (parser.getCurrentToken() == JsonToken.FIELD_NAME) {
        String fieldName = parser.getCurrentName();
        JsonReader.nextToken(parser);
        int fi = FM.get(fieldName);
        try {
            switch(fi) {
                case -1:
                    JsonReader.skipValue(parser);
                    break;
                case FM_size:
                    size = JsonReader.StringReader.readField(parser, fieldName, size);
                    break;
                case FM_bytes:
                    bytes = JsonReader.readUnsignedLongField(parser, fieldName, bytes);
                    break;
                case FM_path:
                    path = JsonReader.StringReader.readField(parser, fieldName, path);
                    break;
                case FM_is_dir:
                    is_dir = JsonReader.BooleanReader.readField(parser, fieldName, is_dir);
                    break;
                case FM_is_deleted:
                    is_deleted = JsonReader.BooleanReader.readField(parser, fieldName, is_deleted);
                    break;
                case FM_rev:
                    rev = JsonReader.StringReader.readField(parser, fieldName, rev);
                    break;
                case FM_thumb_exists:
                    thumb_exists = JsonReader.BooleanReader.readField(parser, fieldName, thumb_exists);
                    break;
                case FM_icon:
                    icon = JsonReader.StringReader.readField(parser, fieldName, icon);
                    break;
                case FM_modified:
                    modified = JsonDateReader.Dropbox.readField(parser, fieldName, modified);
                    break;
                case FM_client_mtime:
                    client_mtime = JsonDateReader.Dropbox.readField(parser, fieldName, client_mtime);
                    break;
                case FM_hash:
                    if (collector == null)
                        throw new JsonReadException("not expecting \"hash\" field, since we didn't ask for children", parser.getCurrentLocation());
                    hash = JsonReader.StringReader.readField(parser, fieldName, hash);
                    break;
                case FM_contents:
                    if (collector == null)
                        throw new JsonReadException("not expecting \"contents\" field, since we didn't ask for children", parser.getCurrentLocation());
                    contents = JsonArrayReader.mk(Reader, collector).readField(parser, fieldName, contents);
                    break;
                case FM_photo_info:
                    photo_info = PendingReader.mk(File.PhotoInfo.Reader, File.PhotoInfo.PENDING).readField(parser, fieldName, photo_info);
                    break;
                case FM_video_info:
                    video_info = PendingReader.mk(File.VideoInfo.Reader, File.VideoInfo.PENDING).readField(parser, fieldName, video_info);
                    break;
                default:
                    throw new AssertionError("bad index: " + fi + ", field = \"" + fieldName + "\"");
            }
        } catch (JsonReadException ex) {
            throw ex.addFieldContext(fieldName);
        }
    }
    JsonReader.expectObjectEnd(parser);
    if (path == null)
        throw new JsonReadException("missing field \"path\"", top);
    if (icon == null)
        throw new JsonReadException("missing field \"icon\"", top);
    if (is_deleted == null)
        is_deleted = Boolean.FALSE;
    if (is_dir == null)
        is_dir = Boolean.FALSE;
    if (thumb_exists == null)
        thumb_exists = Boolean.FALSE;
    if (is_dir && (contents != null || hash != null)) {
        if (hash == null)
            throw new JsonReadException("missing \"hash\", when we asked for children", top);
        if (contents == null)
            throw new JsonReadException("missing \"contents\", when we asked for children", top);
    }
    DbxEntry e;
    if (is_dir) {
        e = new Folder(path, icon, thumb_exists);
    } else {
        // Normal File
        if (size == null)
            throw new JsonReadException("missing \"size\" for a file entry", top);
        if (bytes == -1)
            throw new JsonReadException("missing \"bytes\" for a file entry", top);
        if (modified == null)
            throw new JsonReadException("missing \"modified\" for a file entry", top);
        if (client_mtime == null)
            throw new JsonReadException("missing \"client_mtime\" for a file entry", top);
        if (rev == null)
            throw new JsonReadException("missing \"rev\" for a file entry", top);
        e = new File(path, icon, thumb_exists, bytes, size, modified, client_mtime, rev, photo_info, video_info);
    }
    if (is_deleted) {
        if (allowDeleted) {
            return null;
        } else {
            throw new JsonReadException("not expecting \"is_deleted\" entry here", top);
        }
    }
    return new WithChildrenC<C>(e, hash, contents);
}

9. JsonReader#expectArrayEnd()

Project: dropbox-sdk-java
File: JsonReader.java
public static JsonLocation expectArrayEnd(JsonParser parser) throws IOException, JsonReadException {
    if (parser.getCurrentToken() != JsonToken.END_ARRAY) {
        throw new JsonReadException("expecting the end of an array (\"[\")", parser.getTokenLocation());
    }
    JsonLocation loc = parser.getTokenLocation();
    nextToken(parser);
    return loc;
}

10. JsonReader#expectArrayStart()

Project: dropbox-sdk-java
File: JsonReader.java
public static JsonLocation expectArrayStart(JsonParser parser) throws IOException, JsonReadException {
    if (parser.getCurrentToken() != JsonToken.START_ARRAY) {
        throw new JsonReadException("expecting the start of an array (\"[\")", parser.getTokenLocation());
    }
    JsonLocation loc = parser.getTokenLocation();
    nextToken(parser);
    return loc;
}

11. JsonReader#expectObjectStart()

Project: dropbox-sdk-java
File: JsonReader.java
// ------------------------------------------------------------------
// Delimiter checking helpers.
public static JsonLocation expectObjectStart(JsonParser parser) throws IOException, JsonReadException {
    if (parser.getCurrentToken() != JsonToken.START_OBJECT) {
        throw new JsonReadException("expecting the start of an object (\"{\")", parser.getTokenLocation());
    }
    JsonLocation loc = parser.getTokenLocation();
    nextToken(parser);
    return loc;
}