ignite-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alisher Alimov <alimovalis...@gmail.com>
Subject Using object as key with BinaryMarshaller
Date Tue, 10 Jan 2017 13:30:53 GMT

I have a little problem when try to use object as key with BinaryMarshaller. Bug occurred
only with BinaryMarshaller, on JdkMarshaller all is working fine as expected.

Here is example:

UserObject class used as key that override hashCode and equals methods but seems that BinaryMarshaller
using all fields from key object for building hashCode

private static class UserObject implements Serializable {
    private final Integer id;
    private final Integer notIdField;

    UserObject(Integer id, Integer notIdField) {
        this.id = id;
        this.notIdField = notIdField;

    public Integer getId() {
        return id;

    public Integer getNotIdField() {
        return notIdField;

    public int hashCode() {
        return Objects.hash(id);

    public boolean equals(Object obj) {
        if (obj instanceof UserObject) {
            return Objects.equals(((UserObject) obj).getId(), getId());

        return false;

public void testObjectKey() throws Exception {
    IgniteCache<UserObject, Integer> cache = ignite.getOrCreateCache("test");

    for (int i = 0; i < 10; i++) {
        cache.put(new UserObject(0, i), i);

        Assert.assertEquals(1, cache.size(CachePeekMode.PRIMARY));


Is it expected behaviour or bug?

With best regards
Alisher Alimov

View raw message