0

I have a server and it receives a JSON format message from client, I cast this message to a jackson ObjectNode instance and store it into Hazelcast. This ObjectNode object has a field called 'traceId'. Now I want to search for all object in Hazelcast have equivalent value of 'traceId', using this snippet of code:

EntryObject entry = new PredicateBuilder().getEntryObject();
Predicate predicate = entry.get('traceId').equal(traceId);
return this.cache.search(predicate);

But I got following error:

com.hazelcast.query.QueryException: java.lang.IllegalArgumentException: There is no suitable accessor for 'traceId' on class 'com.fasterxml.jackson.databind.node.ObjectNode'​

If I understand right, ObjectNode class doesn't provide a getter method for field 'traceId'. Anyone knows how to resolve this?

nguyenbkcse
  • 549
  • 1
  • 10
  • 20
  • Why don't you create your own class for recevied message and set its getters-setters instead of ObjectNode? And can you provide this.cache what its declaration type? btw, traceId must be String(double quotes needed) instead of char. – İlker Korkut Dec 23 '19 at 07:35
  • Hi @İlkerKorkut, yes it should be double quotes. The JSON message is usually changed (adding new fields) so to avoid updating the Class representing that JSON message, I use ObjectNode to take advantage of the flexibility of this class (when adding new fields to JSON message, I don't need to do anymore update) – nguyenbkcse Dec 23 '19 at 07:50
  • so you store objectNode, but that objectNode is custom data structure to serialize and deserialize json. but in this way it seems objectNode keep fields as map and it can iterate maps and you can reach their field's values via json node etc.. so you cant query objectNode's maps like this. Just need a serializable pojo class and reach them on cache. – İlker Korkut Dec 23 '19 at 08:28
  • @İlkerKorkut, what is the meaning of your last sentence. Does it mean, I need to create a wrapper class for ObjectNode and in this class I provide a field called 'traceId'? – nguyenbkcse Dec 23 '19 at 08:44
  • yes it's an another option if needed in this case. But my sugesstion was that; create your json model in java as serializable object and store them. If any change on your json of course you need to change your model too, but via model versioning you can handle also this situation i think. – İlker Korkut Dec 23 '19 at 08:55

0 Answers0