anvesh mora
anvesh mora

Reputation: 23

Need Help on JsonSerializer Hazelcast-client

I'm trying to implement NoSql solution with Hazelcast-client(Node Js) using Predicates.

I'm creating a users map as below:


    function generateUsers(users) {
        return users.put('Rod', new User('Rod', 19, true)).then(function () {
            var usertemp={
                username: "Jane",
                age: 20,
                active: true
            };
            //return users.put('Jane', new User('Jane', 20, true));
            return users.put('Jane', usertemp);
        }).then(function () {
            var usertemp={
                username: "Freddy",
                age: 23,
                active: true
            };
            return users.put('Freddy', usertemp);
        }).then(function(){
            var usertemp={
                username: "test",
                age: 20,
                active: false
            };
           //var usertemp2= new User('Test',20,true);
            users.put('test',usertemp);
            console.log("after put");
            console.log("Userdata:"+users);
            return users;
        });
    }

And when I try to query for an entry in map using predicate it is giving the exception, below is the code I'm using for querying the Map using Predicate


    var JsonSerializer = /** @class */ (function () {
        function JsonSerializer() {
        }
        JsonSerializer.prototype.getId = function () {
            return 1;
        };
        JsonSerializer.prototype.read = function (input) {
            return JSON.parse(input.readUTF());
        };
        JsonSerializer.prototype.write = function (output, object) {
            output.writeUTF(JSON.stringify(object));
        };
        return JsonSerializer;
    }());

    var cfg = new Config.ClientConfig();
    cfg.serializationConfig.customSerializers =[new JsonSerializer(),];
    cfg.serializationConfig.portableFactories[1] = new PortableFactory();
    // Start the Hazelcast Client and connect to an already running Hazelcast Cluster on 127.0.0.1
    Client.newHazelcastClient(cfg).then(function (hz) {
        // Get a Distributed Map called "users"
        var users = hz.getMap('users');
        // Add some users to the Distributed Map
        return generateUsers(users).then(function () {
            // Create a Predicate
            var criteriaQuery = Predicates.and(
                Predicates.truePredicate('active', true),
                Predicates.isBetween('age', 18, 21)
            );
            // Get result collections using the the Predicate
            console.log("before valuesWithPredicate");
            return users.valuesWithPredicate(criteriaQuery);
        }).then(function (values) {
            // Print out the results
            console.log(values.toArray());
            // Shutdown this Hazelcast Client
            hz.shutdown();
        })
    });

Below is the Exception:


    Unhandled rejection Error: There is no suitable de-serializer for type -130. This exception is likely to be caused by differences in the serialization configuration between members or between clients and members.
    
> NOTE: I've Tried adding customSerializer JsonSerializer  in HazelcastClient config



Edit1: I've missed hazlecast server console, seems like we need to have similiar Serializer configured on hazlecast server, below is the exception

<pre>
SEVERE: [10.8.162.33]:5701 [dev] [3.10.5] There is no suitable de-serializer for type -130. This exception is likely to be caused by differences in the serialization configuration between members or between clients and members.
com.hazelcast.nio.serialization.HazelcastSerializationException: There is no suitable de-serializer for type -130. This exception is likely to be caused by differences in the serialization configuration between members or between clients and members.
        at com.hazelcast.internal.serialization.impl.AbstractSerializationService.newHazelcastSerializationException(AbstractSerializationService.java:238)
        at com.hazelcast.internal.serialization.impl.AbstractSerializationService.toObject(AbstractSerializationService.java:182)
        at com.hazelcast.query.impl.CachedQueryEntry.getValue(CachedQueryEntry.java:75)
        at com.hazelcast.query.impl.CachedQueryEntry.getTargetObject(CachedQueryEntry.java:108)
        at com.hazelcast.query.impl.QueryableEntry.extractAttributeValue(QueryableEntry.java:81)
        at com.hazelcast.query.impl.QueryableEntry.getAttributeValue(QueryableEntry.java:48)
        at com.hazelcast.query.impl.predicates.AbstractPredicate.readAttributeValue(AbstractPredicate.java:132)
        at com.hazelcast.query.impl.predicates.AbstractPredicate.apply(AbstractPredicate.java:57)
        at com.hazelcast.query.impl.predicates.AndPredicate.apply(AndPredicate.java:136)
        at com.hazelcast.map.impl.query.PartitionScanRunner.run(PartitionScanRunner.java:97)
        at com.hazelcast.map.impl.query.CallerRunsPartitionScanExecutor.execute(CallerRunsPartitionScanExecutor.java:42)
        at com.hazelcast.map.impl.query.QueryRunner.runPartitionScanQueryOnGivenOwnedPartition(QueryRunner.java:172)
        at com.hazelcast.map.impl.query.QueryPartitionOperation.run(QueryPartitionOperation.java:45)
        at com.hazelcast.spi.Operation.call(Operation.java:148)
        at com.hazelcast.spi.impl.operationservice.impl.OperationRunnerImpl.call(OperationRunnerImpl.java:202)
        at com.hazelcast.spi.impl.operationservice.impl.OperationRunnerImpl.run(OperationRunnerImpl.java:191)
        at com.hazelcast.spi.impl.operationexecutor.impl.OperationThread.process(OperationThread.java:120)
        at com.hazelcast.spi.impl.operationexecutor.impl.OperationThread.run(OperationThread.java:100)

But unfortuntely, I'm not able to find similar JSONSerializer on Server side to configure in hazlecast.xml

Upvotes: 1

Views: 1232

Answers (1)

mustafaiman
mustafaiman

Reputation: 71

-130 is the serialization id reserved for Hazelcast Node.js Client. Hazelcast server currently does not support native JSON serialization but it is planned for the next release: https://www.infoq.com/news/2018/08/hazelcast-new-ceo

We are also planning on introducing new data structures, enhancing query with SQL Select and JDBC, and adding native JSON support for document-oriented systems. So more than ever to do and busy as ever.

As a workaround you can use Portable serialization for your complex objects. You need to write your own serializers on both client and server sides. Then, the server should be able to query your objects. Keep in mind that you need to use a positive serialization id for your serializers. Negative ids are reserved for internal serializers and cannot be overridden.

www.hazelcast.org has a nice sample for implementing portable serialization. Just look for Portable Serializer sample under Java Member and Node.js tabs.

Upvotes: 1

Related Questions