com.fasterxml.jackson.databind.JsonMappingException#getPath ( )源码实例Demo

下面列出了com.fasterxml.jackson.databind.JsonMappingException#getPath ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: act-platform   文件: MapperUtils.java
/**
 * 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;
}
 
源代码2 项目: heroic   文件: JsonMappingExceptionMapper.java
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();
}