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

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

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

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)

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

It works perfectly. Thanks a lot!