You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Josh Bronson <jb...@macromedia.com> on 2004/06/30 20:22:54 UTC

[Digester] Not Converting String to Int

 I'm using Digester to map my XML file to my Java class, Restaurant.
Restaurant has a number of instance variables, most of which are Strings,
but some are ints. Digester is successfully calling the Restaurant setter
methods for the String instance variables, but it throws an exception
whenever it tries to call a setter method for an instance variable of type
int. For example, when it tries to call Restaurant.setId, it throws a
java.lang.NoSuchMethodException: No such accessible method: setId() on
object: Restaurant. I can work around this: If I change the setId method to
take a String and then use Integer.parseInt() to assign id, then I do not
get the error. But according to the AddressBook sample that came with
Digester, Digester should be converting all Strings it encounters in the XML
file to the appropriate types specified by the setter method signatures of
Restaurant, but obviously it isn't. Any help?

Thanks!

josh


Here is an excerpt from the XML file I'm parsing:


<restaurants>
  <restaurant>
    <id>0</id>
    <name>My Restaurant</name>
    <address>123 Sesame Street</address>
    <city>Cityville</city>
    <zip>12345</zip>
    <phone>(123) 123-4567</phone>
    <link>http://myrestaurant.com</link>
    <image>myrestaurant.jpg</image>
    <comments>blah blah blah</comments>
    <area_id>5</area_id>
    <map_x>6</map_x>
    <map_y>189</map_y>
    <categories>
      <category>American</category>
      <category>French</category>
    </categories>
  </restaurant>
  ...
</restaurants>




---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: [Digester] Not Converting String to Int

Posted by Josh Bronson <jb...@macromedia.com>.
nevermind, i figured it out. It's all about the fourth parameter of 
addCallMethod(). I just passed it

new Class[] {Integer.class}

and it worked.




---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org