I am working through the book 'Spring MVC, Beginners Guide'. In one section it suggests using Matrix Variables to pass in a high and low price. In their example the declaration specifies a List of Strings as the second parameter (see below).
@MatrixVariable(pathVar="price") Map<String, List<String>> priceParams
However, as there will only ever be one value for each key, I thought I would try the declaration :
@MatrixVariable(pathVar="price") Map<String, String> priceParams
When I try to access the 'value' associated with a specific key stored in the Map
(using iterator.getKey()
and iterator.getValue()
, I continually get a run time ClassCastException
error.
"Request processing failed; nested exception is java.lang.ClassCastException: java.util.LinkedList cannot be cast to java.lang.String"
I have tried different data types e.g. Integer
, BigInteger
, Double
, Float
and the error is always the same (apart from it not being a String
)
when I examine the priceParams in debug, the data type shows as a LinkedMultiValueMap
and the target map as a LinkedHashMap
.
I am beginning to suspect that it is not possible to declare a Matrix Variable using Map<K,V>
but only Map<K, List<V>>
Declaring it in the form Map<K, List<V>>
works but you have to cycle through all the entries in the List
, even though only one exists.
Any help would certainly be appreciated