Import Array or List to as value to Map object with Spring bean config
Mike Cheung
Greenhorn
Joined: Feb 01, 2013
Posts: 9
posted
0
Hi, need some guidance on how best to do this. While the following class would work in taking in all the comma separated subjects as provided in the XML.
How do I make it such that the values taken in to the map isn't just a simple String but an Array of class or a List of class? For example, following is the code that I want to use.....
Array style
List style
Tried the Array style but was welcomed with the following type of exception.
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name ......: Failed to convert value of type 'java.lang.String' to required type 'org.highschool.Subject'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [org.highschool.Subject]: no matching editors or conversion strategy found
First, I would use the <util:map> version just because there are more features.
But when it comes to Entries there are a good three different ways.
The first way you printed would only allow Strings for key and value, unless you used <entry key-ref="someOtherObject" value-ref="someOtherObjectWhichCouldBeAList"/>
but there is also the <key> tag, and of course, <ref bean=""> and <value> tags for the value.
So here is an example with your Map<String, Subject[]>