@Override public T build(ConfigurationSourceProvider provider, String path) throws IOException, ConfigurationException { try (InputStream input = provider.open(requireNonNull(path))) { final JsonNode node = mapper.readTree(createParser(input)); if (node == null) { throw ConfigurationParsingException .builder("Configuration at " + path + " must not be empty") .build(path); } return build(node, path); } catch (JsonParseException e) { throw ConfigurationParsingException .builder("Malformed " + formatName) .setCause(e) .setLocation(e.getLocation()) .setDetail(e.getMessage()) .build(path); } }
protected T read(String content) throws IOException { log.debug("Reading {} from \"{}\".", valueType, content); try (InputStream in = IOUtils.toInputStream(content, ENCODING)) { return objectMapper.readValue(in, valueType); } catch (JsonParseException e) { String msg = String.format("Parse from \"%1$s\" failed: %2$s", content, e.getMessage()); throw new JsonParseException(msg, e.getLocation(), e); } }
public Response toResponse(final JsonParseException exception) { logger.debug("Mapping JsonParseException to SerializationErrorResponseDto...", exception); String message; if(exception.getLocation() != null) { message = String.format(MESSAGE_WITH_LOCATION, exception.getLocation().getLineNr(), exception.getLocation().getColumnNr(), exception.getOriginalMessage()); } else { message = String.format(MESSAGE_WITHOUT_LOCATION, exception.getOriginalMessage()); } IdentityApiErrorResponseDto e = new SerializationErrorResponseDto(message); final Response result = Response.status(e.getResponseStatusCode()) .entity(e) .type(httpHeaders.getMediaType()) .build(); logger.trace("Done mapping JsonParseException to SerializationErrorResponseDto."); return result; } }
String line = "unknown"; String column = "unknown"; if (e.getLocation() != null) { line = String.valueOf(e.getLocation().getLineNr()); column = String.valueOf(e.getLocation().getColumnNr());
protected void handleAndRaise(String suffix, Exception e) throws UserException { String message = e.getMessage(); int columnNr = -1; if (e instanceof JsonParseException) { final JsonParseException ex = (JsonParseException) e; message = ex.getOriginalMessage(); columnNr = ex.getLocation().getColumnNr(); } UserException.Builder exceptionBuilder = UserException.dataReadError(e) .message("%s - %s", suffix, message); if (columnNr > 0) { exceptionBuilder.pushContext("Column ", columnNr); } if (hadoopPath != null) { exceptionBuilder.pushContext("Record ", currentRecordNumberInFile()) .pushContext("File ", hadoopPath.toUri().getPath()); } throw exceptionBuilder.build(logger); }
protected void handleAndRaise(String suffix, Exception e) throws UserException { String message = e.getMessage(); int columnNr = -1; if (e instanceof JsonParseException) { final JsonParseException ex = (JsonParseException) e; message = ex.getOriginalMessage(); columnNr = ex.getLocation().getColumnNr(); } UserException.Builder exceptionBuilder = UserException.dataReadError(e) .message("%s - %s", suffix, message); if (columnNr > 0) { exceptionBuilder.pushContext("Column ", columnNr); } if (hadoopPath != null) { exceptionBuilder.pushContext("Record ", currentRecordNumberInFile()) .pushContext("File ", hadoopPath.toUri().getPath()); } throw exceptionBuilder.build(logger); }
@Override public T fromBytes(final byte[] bytes) { try { try { return mapper.readValue(bytes, clazz); } catch (final JsonParseException ex) { final JsonLocation location = ex.getLocation(); Object src = location.getSourceRef(); if (src instanceof ByteBuffer) { src = ((ByteBuffer) src).asCharBuffer(); } else if (src instanceof byte[]) { src = new String((byte[]) src); } else if (src instanceof char[]) { src = new String((char[]) src); } throw new JsonParseException( ex.getMessage(), new JsonLocation( src, location.getByteOffset(), location.getCharOffset(), location.getLineNr(), location.getColumnNr()), ex.getCause()); } } catch (final IOException ex) { throw new RuntimeException(ex); } } }
@Override public T build(ConfigurationSourceProvider provider, String path) throws IOException, ConfigurationException { try (InputStream input = provider.open(requireNonNull(path))) { final JsonNode node = mapper.readTree(createParser(input)); if (node == null) { throw ConfigurationParsingException .builder("Configuration at " + path + " must not be empty") .build(path); } return build(node, path); } catch (JsonParseException e) { throw ConfigurationParsingException .builder("Malformed " + formatName) .setCause(e) .setLocation(e.getLocation()) .setDetail(e.getMessage()) .build(path); } }
@Override public T build(ConfigurationSourceProvider provider, String path) throws IOException, ConfigurationException { try (InputStream input = provider.open(requireNonNull(path))) { final JsonNode node = mapper.readTree(createParser(input)); if (node == null) { throw ConfigurationParsingException .builder("Configuration at " + path + " must not be empty") .build(path); } return build(node, path); } catch (JsonParseException e) { throw ConfigurationParsingException .builder("Malformed " + formatName) .setCause(e) .setLocation(e.getLocation()) .setDetail(e.getMessage()) .build(path); } }
JsonLocation loc = jpe.getLocation(); validationResults.add(getErrorResult(msg, getLineOffset(schemaNode) + loc.getLineNr(), globaSchemaIncludeInfo));
JsonLocation loc = jpe.getLocation(); validationResults.add(getErrorResult(msg, getLineOffset(schemaNode) + loc.getLineNr(), globaSchemaIncludeInfo));
JsonLocation location = e.getLocation(); String locationOfError = "(unavailable)"; if (location != null && location != JsonLocation.NA) {
JsonLocation location = e.getLocation(); String locationOfError = "(unavailable)"; if (location != null && location != JsonLocation.NA) {
private static JsonNode readNode(final MappingIterator<JsonNode> iterator) throws IOException { final Object source = iterator.getParser().getInputSource(); final JsonParseExceptionBuilder builder = new JsonParseExceptionBuilder(source); builder.setMessage(BUNDLE.getMessage("read.noContent")); if (!iterator.hasNextValue()) throw builder.build(); final JsonNode ret = iterator.nextValue(); builder.setMessage(BUNDLE.getMessage("read.trailingData")) .setLocation(iterator.getCurrentLocation()); try { if (iterator.hasNextValue()) throw builder.build(); } catch (JsonParseException e) { throw builder.setLocation(e.getLocation()).build(); } return ret; }
private static JsonNode readNode(final MappingIterator<JsonNode> iterator) throws IOException { final Object source = iterator.getParser().getInputSource(); final JsonParseExceptionBuilder builder = new JsonParseExceptionBuilder(source); builder.setMessage(BUNDLE.getMessage("read.noContent")); if (!iterator.hasNextValue()) throw builder.build(); final JsonNode ret = iterator.nextValue(); builder.setMessage(BUNDLE.getMessage("read.trailingData")) .setLocation(iterator.getCurrentLocation()); try { if (iterator.hasNextValue()) throw builder.build(); } catch (JsonParseException e) { throw builder.setLocation(e.getLocation()).build(); } return ret; }