【问题标题】:Why is Spring Data Neo4J Ignoring @JsonIgnore?为什么 Spring Data Neo4J 忽略 @JsonIgnore?
【发布时间】:2015-07-15 09:23:41
【问题描述】:

使用以下@NodeEntity

@NodeEntity
public class Person extends BasePersistenceObject {

    @GraphId
    Long id;

    String fullName;

    @Indexed(unique=true)
    String email;

    String passwordHash = null;

    @JsonIgnore
    public String getPasswordHash() {
        return passwordHash;
    }

    ...
}

我仍然在以下控制器方法的 JSON 响应中看到 passwordHash:

@RequestMapping(value = "/login", method=RequestMethod.POST)
public @ResponseBody Person login(@RequestBody Map<String, String> credentials, HttpServletRequest request) throws AuthorizationException {

    String email = credentials.get("email");
    String password = credentials.get("password");
    String ipAddress = request.getRemoteAddr();

    return authService.authenticate(email, password, ipAddress);

}

【问题讨论】:

标签: java spring neo4j spring-data-neo4j


【解决方案1】:

Spring Data Neo4J 与 JSON 序列化无关,这是 Spring MVC 和 Jackson 或 Gson 的责任,具体取决于您使用的内容。所以请确保 Jackson 用于 JSON 序列化,否则注释将不起作用。

【讨论】:

  • 我的印象是 Spring Boot 默认使用 Jackson 来进行编组。如何检查?
  • 默认情况下它使用杰克逊,这是正确的。但它也支持 Gson,所以如果 Gson 在你的类路径上,它可能会使用它。检查你的依赖树 (mvn dependency:tree),如果某处有 Gson 依赖。如果类路径上有 spring-boot-starter-actuator(并且如果它是 Spring boot 应用程序),您还可以检查 REST 端点 /autoconfig 或 /beans,如果定义了任何 Gson 或 Jackson bean。
猜你喜欢
  • 1970-01-01
  • 2016-08-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-11-13
  • 1970-01-01
  • 1970-01-01
  • 2021-03-11
相关资源
最近更新 更多