本文整理匯總了Java中com.fasterxml.jackson.core.JsonLocation.getLineNr方法的典型用法代碼示例。如果您正苦於以下問題:Java JsonLocation.getLineNr方法的具體用法?Java JsonLocation.getLineNr怎麽用?Java JsonLocation.getLineNr使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.fasterxml.jackson.core.JsonLocation
的用法示例。
在下文中一共展示了JsonLocation.getLineNr方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getTokenLocation
import com.fasterxml.jackson.core.JsonLocation; //導入方法依賴的package包/類
@Override
public XContentLocation getTokenLocation() {
JsonLocation loc = parser.getTokenLocation();
if (loc == null) {
return null;
}
return new XContentLocation(loc.getLineNr(), loc.getColumnNr());
}
示例2: initializeJsonLocation
import com.fasterxml.jackson.core.JsonLocation; //導入方法依賴的package包/類
private void initializeJsonLocation(@Nullable JsonLocation jsonLoc) {
if (jsonLoc == null) {
return;
}
this.charOffset = ((int) jsonLoc.getCharOffset());
this.colNum = jsonLoc.getColumnNr();
this.lineNum = jsonLoc.getLineNr();
}
示例3: build
import com.fasterxml.jackson.core.JsonLocation; //導入方法依賴的package包/類
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;
}
示例4: createLocation
import com.fasterxml.jackson.core.JsonLocation; //導入方法依賴的package包/類
private Location createLocation(JsonLocation json) {
return new Location(json.getLineNr() - 1, json.getColumnNr() - 1);
}
示例5: toResponse
import com.fasterxml.jackson.core.JsonLocation; //導入方法依賴的package包/類
/**
* {@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();
}