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?
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
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.