Java Code Examples for com.fasterxml.jackson.databind.JsonMappingException#getPath()

The following examples show how to use com.fasterxml.jackson.databind.JsonMappingException#getPath() . 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: MapperUtils.java    From act-platform with ISC License 6 votes vote down vote up
/**
 * Helper function to construct a string representation of a property path from a JsonMappingException
 * (similar to a property path from a ConstraintViolationException).
 *
 * @param exception JsonMappingException
 * @return String representation of property path
 */
static String printPropertyPath(JsonMappingException exception) {
  if (CollectionUtils.isEmpty(exception.getPath())) return "UNKNOWN";

  String propertyPath = "";
  for (JsonMappingException.Reference ref : exception.getPath()) {
    if (ref.getFieldName() != null) {
      if (!propertyPath.isEmpty()) {
        propertyPath += ".";
      }

      propertyPath += ref.getFieldName();
    } else {
      propertyPath += String.format("[%d]", ref.getIndex());
    }
  }

  return propertyPath;
}
 
Example 2
Source File: JsonMappingExceptionMapper.java    From heroic with Apache License 2.0 6 votes vote down vote up
private String constructPath(final JsonMappingException e) {
    final StringBuilder builder = new StringBuilder();

    final Consumer<String> field = name -> {
        if (builder.length() > 0) {
            builder.append(".");
        }

        builder.append(name);
    };

    for (final JsonMappingException.Reference reference : e.getPath()) {
        if (reference.getIndex() >= 0) {
            builder.append("[" + reference.getIndex() + "]");
        } else {
            field.accept(reference.getFieldName());
        }
    }

    if (e.getCause() instanceof Validation.MissingField) {
        final Validation.MissingField f = (Validation.MissingField) e.getCause();
        field.accept(f.getName());
    }

    return builder.toString();
}