杰克逊,哈希密码未被映射

时间:2014-09-27 17:23:05

标签: java mongodb jackson mongo-jackson-mapper mongojack

我有以下收藏“玩家”

{
    "_id" : ObjectId("5426efb844ae829d1dcdaa6d"),
    "username" : "Foobar",
    "password" : "0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33",
    "gameIds" : [
            "5426f10544ae8502f731d8a0"
    ]
}

它有一个哈希密码。 当我尝试将直接映射回我的Player对象时,除了密码之外的所有内容都被映射。密码为空。

这是我的映射播放器

@Data
@JsonRootName("player")
@NoArgsConstructor
public class Player {
    @JsonIgnore
    public static final String COL_NAME = "player";

    @ObjectId
    @Id
    private String id;

    /**Will use this token to authorize the user. This UUID should be cached once the user logs in */
    @JsonIgnore
    private UUID token = UUID.randomUUID();

    @NotBlank
    //Unique
    private String username;

    @Email
    private String email;

    @NotBlank
    private String password;

    /** Set of unique active games * */
    private Set<String> gameIds = new HashSet<>();
}

我正在保存播放器:

    Player player = new Player();
    player.setUsername(username);
    player.getGameIds().add(pbfId);
    player.setPassword(DigestUtils.sha1Hex("foo"));
    playerCollection.insert(player);

阅读这样:

DBCursor<Player> username = playerCollection.find(DBQuery.is("username", "Foobar"), new BasicDBObject());
Player player = username.next();

此处除密码以外的所有内容都已正确映射

1 个答案:

答案 0 :(得分:0)

我不知道发生了什么,但似乎我查询了错误的数据库。我不知道这是怎么发生的。

在违反正确的数据库之后,它运行良好