# Writing a map to an aerospike bin corrupting the aerospike data

**URL:** <https://discuss.aerospike.com/t/writing-a-map-to-an-aerospike-bin-corrupting-the-aerospike-data/2637>\
**Category:** General Discussion\
**Tags:** java\
**Created:** [March 16, 2016, 12:19pm UTC](https://discuss.aerospike.com/t/writing-a-map-to-an-aerospike-bin-corrupting-the-aerospike-data/2637 "2016-03-16T12:19:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sathiya\_Cm](https://avatars.discourse-cdn.com/v4/letter/s/4491bb/32.png) [@Sathiya\_Cm](https://discuss.aerospike.com/u/Sathiya_Cm)\
**Post date:** [March 16, 2016, 12:19pm UTC](https://discuss.aerospike.com/t/writing-a-map-to-an-aerospike-bin-corrupting-the-aerospike-data/2637/1 "2016-03-16T12:19:15Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![rbotzer](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/rbotzer/32/2114_2.png) [@rbotzer](https://discuss.aerospike.com/u/rbotzer)\
**Post date:** [March 16, 2016, 7:11pm UTC](https://discuss.aerospike.com/t/writing-a-map-to-an-aerospike-bin-corrupting-the-aerospike-data/2637/2 "2016-03-16T19:11:49Z")

</div>

Which version of the server and Java client are you using? In general, if a type on the application side is not supported on the server-side, the client will serialize it and store it as bytes.

The double data type has been supported on the server since 3.6.0 and the Java client since its 3.1.4 release.
