# Need help on params.get() in Native Java Script

**URL:** <https://discuss.elastic.co/t/need-help-on-params-get-in-native-java-script/40326>\
**Category:** Elasticsearch\
**Created:** [January 28, 2016, 7:02am UTC](https://discuss.elastic.co/t/need-help-on-params-get-in-native-java-script/40326 "2016-01-28T07:02:45Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![cuongvt101](https://avatars.discourse-cdn.com/v4/letter/c/dc4da7/32.png) [@cuongvt101](https://discuss.elastic.co/u/cuongvt101)\
**Post date:** [January 28, 2016, 7:02am UTC](https://discuss.elastic.co/t/need-help-on-params-get-in-native-java-script/40326/1 "2016-01-28T07:02:45Z")

</div>

I am facing an issue in using params.get(). Suppose one of my params is a weights vector of double, so in theory I can read as:

`weights = (ArrayList<Double>) params.get("weights");`

However, if it happens that my weights vector contains integer value (e.g., `weights = {1.2, 3, 4.5}`), the above line will throw an error of cannot cast from Integer to Double. One of the solution is trying to recreate the weights vector so that it appears as `{1.2, 3.0, 4.5}` in JSON. However, I would prefer the ability to read correctly from the version `{1.2, 3, 4.5}`. Is it possible and how can I do that?

Thanks

---

<div class="post-metadata">

**Author:** ![cuongvt101](https://avatars.discourse-cdn.com/v4/letter/c/dc4da7/32.png) [@cuongvt101](https://discuss.elastic.co/u/cuongvt101)\
**Post date:** [January 28, 2016, 1:29pm UTC](https://discuss.elastic.co/t/need-help-on-params-get-in-native-java-script/40326/2 "2016-01-28T13:29:44Z")

</div>

Or can someone point me to the source code of params.get(), I'll have a closer look. Haven't got any luck so far. Thanks

---

<div class="post-metadata">

**Author:** ![colings86](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/colings86/32/44960_2.png) [@colings86](https://discuss.elastic.co/u/colings86)\
**Post date:** [January 28, 2016, 2:08pm UTC](https://discuss.elastic.co/t/need-help-on-params-get-in-native-java-script/40326/3 "2016-01-28T14:08:38Z")

</div>

You could probably cast to an `ArrayList<Number>` instead and then use the `Number.doubleValue()` method to get the value of each element (Note I haven't tried this myself)

---

<div class="post-metadata">

**Author:** ![colings86](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/colings86/32/44960_2.png) [@colings86](https://discuss.elastic.co/u/colings86)\
**Post date:** [January 28, 2016, 2:11pm UTC](https://discuss.elastic.co/t/need-help-on-params-get-in-native-java-script/40326/4 "2016-01-28T14:11:08Z")

</div>

by the way, as far as I know `params` is just a standard java.util.HashMap object

When the JSON is deserialised to build the params map it will deserialise the array using a generic method that probably output a `List<Object>`so the actual elements in theory could be anything. If you know you are only putting numbers into the array then casting to `List<Number>` as I mentioned above should hopefully work

---

<div class="post-metadata">

**Author:** ![cuongvt101](https://avatars.discourse-cdn.com/v4/letter/c/dc4da7/32.png) [@cuongvt101](https://discuss.elastic.co/u/cuongvt101)\
**Post date:** [January 28, 2016, 6:43pm UTC](https://discuss.elastic.co/t/need-help-on-params-get-in-native-java-script/40326/5 "2016-01-28T18:43:19Z")

</div>

It works perfectly. Thanks a lot!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 5, 2017, 11:20pm UTC](https://discuss.elastic.co/t/need-help-on-params-get-in-native-java-script/40326/6 "2017-07-05T23:20:40Z")

</div>


