I want to write a map bin to aerospike using Java client The bin should finally look like
{2890:0.75}
and here is my code
HashMap<String, String> newMap = new HashMap<String, String>(); JsonArray infArray = jsonData.get("inferences").getAsJsonArray(); for (int i = 0; i < infArray.size(); i++) { JsonObject currentInference = infArray.get(i).getAsJsonObject(); String attrId = currentInference.get("attributeId").getAsString(); String weight = currentInference.get("weight").getAsString(); newMap.put(attrId, weight); } Bin infBin = new Bin("inferences", Value.get(newMap)); client.put(null, key, infBin);
The issue is when I am writing the bin to aerospike the data is getting corrupted or may be getting encoded whatsoever. For example the map
(inferences:{0=0, 2890=0.75})
is getting converted to
AC ED 00 05 73 72 00 11 6A 61 76 61 2E 75 74 69 6C 2E 48 61 73 68 4D 61 70 05 07 DA C1 C3 16 60 D1 03 00 02 46 00 0A 6C 6F 61 64 46 61 63 74 6F 72 49 00 09 74 68 72 65 73 68 6F 6C 64 78 70 3F 40 00 00 00 00 00 0C 77 08 00 00 00 10 00 00 00 02 74 00 04 33
I am not sure as to why this is happening. Any help would be of great help as I am totally stuck with this issue. Thanks in advance
Edit 1 : Now, there is some interesting thing happening.
I modified the above code as
Bin infBin = new Bin(“inferences”, Value.getAsMap(newMap));
Also modified the HashMap to use Integer and Double as below
HashMap<Integer, Double> newMap = new HashMap<Integer, Double>();
JsonArray infArray = jsonData.get("inferences").getAsJsonArray();
for (int i = 0; i < infArray.size(); i++) {
JsonObject currentInference = infArray.get(i).getAsJsonObject();
Integer attrId = currentInference.get("attributeId").getAsInt();
Double weight = currentInference.get("weight").getAsDouble();
newMap.put(attrId, weight);
}
Bin infBin = new Bin("inferences", Value.get(newMap));
client.put(null, key, infBin);
Now the first key of the map is getting written correctly to aerospike. But the value is still having the issue.
Then I modified the code again to use Float instead of Double. Then both the keys are getting written correctly of the map are getting written correctly without any issue. But the value is still having the issue.
Then as a final try I modified the Float also as Integer and tried then the aerospike is getting updated properly without any issue. Does this mean that Double and Float are not supported by aerospike Java client?