为什么Spring Data Neo4J忽略@JsonIgnore?

时间:2015-05-05 14:54:52

标签: java spring neo4j spring-data-neo4j

使用以下@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);

}

1 个答案:

答案 0 :(得分:0)

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