aspose file tools*
The moose likes Spring and the fly likes Import Array or List to as value to Map object with Spring bean config Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Import Array or List to as value to Map object with Spring bean config" Watch "Import Array or List to as value to Map object with Spring bean config" New topic
Author

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

Mike Cheung
Ranch Hand

Joined: Feb 01, 2013
Posts: 93
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

Joined: Feb 05, 2001
Posts: 17259
    
    6

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">


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Import Array or List to as value to Map object with Spring bean config