• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

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

 
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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">
 
reply
    Bookmark Topic Watch Topic
  • New Topic