Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Import Array or List to as value to Map object with Spring bean config

 
Mike Cheung
Ranch Hand
Posts: 113
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Mark Spritzler
ranger
Sheriff
Posts: 17276
6
IntelliJ IDE Mac Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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[]>



That is one way to do it.

Mark">
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic