Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: How to define a map of Long values

  1. #1
    Join Date
    Mar 2005
    Posts
    10

    Default How to define a map of Long values

    Hi,

    I am trying to define a map of Long/Integer values. I have tried the following but the map values are of type String.

    <map>
    <entry key="K1">
    <value>30000</value>
    </entry>
    <entry key="K2">
    <value>20000</value>
    </entry>
    <entry key="K3">
    <value>20000</value>
    </entry>
    </map>

    I understand that you can't have primitive types (int/long) in a map. So it has to be a Integer/Long. Similar XML in simple properties converts them to integers. I am wondering if there is a way I can specify the type of the value.

    I'd be grateful if someone can shed some light on this.
    Thanks

    Roshan

  2. #2
    Join Date
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    1,104

    Default

    Try:
    Code:
    <entry key="K1">
      <bean id="num" class="java.lang.Long">
        <constructor-arg><value>30000</value></constructor-arg>
      </bean>
    </entry>

  3. #3
    Join Date
    Aug 2004
    Location
    Toronto, Canada
    Posts
    736

    Default

    You should be able to use the 'type' attribute for value, i.e.

    <value type="java.lang.Long">30000</value>


    Regards,
    Colin Sampaleanu
    SpringSource - http://www.springsource.com

  4. #4
    Join Date
    Mar 2005
    Posts
    10

    Default

    Hi,

    Thanks for the replies.

    I tried

    Code:
     <value type="java.lang.Long">30000</value>
    but then I get an XML parser error.

    Sorry forgot to mention I am using Spring 1.1.4.

    I looked at http://www.springframework.org/dtd/spring-beans.dtd and it doesn't seems to have such an attribute.

    Did I miss something?

    Regards,
    Roshan

  5. #5
    Join Date
    Aug 2004
    Location
    Toronto, Canada
    Posts
    736

    Default

    Sorry, I sometimes forget that not everybody is living off CVS. This is something that's been added for Spring 1.2. 1.2RC1 should actually be oiut tomorrow, but obviously if you need this in production now, that's somewhat problematic.

    Regards,
    Colin Sampaleanu
    SpringSource - http://www.springsource.com

  6. #6
    Join Date
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    1,104

    Default

    <value type="java.lang.Long">30000</value>
    That's much nicer.

    If not upgrading to 1.2RC1 yet, you can use my post in the meantime.

  7. #7
    Join Date
    Apr 2005
    Location
    Melbourne, Australia
    Posts
    32

    Default what about key types? can they be non string?

    See title
    Cheers,

    Bonny Rais

  8. #8
    Join Date
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    1,104

    Default

    what about key types? can they be non string?
    Yep added in 1.2 RC1. See JIRA SPR-392

  9. #9
    Join Date
    Apr 2005
    Location
    Melbourne, Australia
    Posts
    32

    Default

    Quote Originally Posted by katentim
    what about key types? can they be non string?
    Yep added in 1.2 RC1. See JIRA SPR-392
    thanks, I'll have a look at that.

    The reference document does not mention it - should be added.
    Cheers,

    Bonny Rais

  10. #10
    Join Date
    Apr 2005
    Location
    Melbourne, Australia
    Posts
    32

    Default Class typed keys

    Note: Spring 1.2

    I'm trying to set the keys of the map as class types, but get a type
    mismatch conversion exception. My bean file looks like:
    Code:
                <map>
                    <entry>
                        <key>
                            <value type="....finders.NEFinder"/>
                        </key>
                        <ref bean="defaultNEFinder"/>
                    </entry>
               </map>
    It seems that spring wants to instantiate an instance of the shown type
    with some value, but I simply want the class itself as the value of the key.

    I'm sure I'm doing something wrong here, but what?
    Cheers,

    Bonny Rais

Similar Threads

  1. MySQL DDL
    By analogueboy in forum Security
    Replies: 5
    Last Post: Aug 17th, 2007, 03:48 PM
  2. Replies: 2
    Last Post: Sep 22nd, 2005, 04:11 PM
  3. Binding Long Values with CustomNumberEditor
    By chichirico in forum Web
    Replies: 0
    Last Post: Jun 21st, 2005, 11:02 AM
  4. Replies: 2
    Last Post: May 5th, 2005, 09:35 PM
  5. Long or long ????
    By mia in forum Web
    Replies: 2
    Last Post: May 5th, 2005, 10:02 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •