commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Paul Smith <>
Subject [Digester]: Primitives & Object create rules help
Date Tue, 25 Feb 2003 06:05:02 GMT
Firstly, I am still pretty new to Digester.

I am needing to use Digester to read xml of the form of this test case:
  public void test1() throws Exception
    String xml = "<Collection>" +
                        "  <ID>1</ID> " +

   Digester digester = new Digester();
   digester.addObjectCreate("Collection", java.util.ArrayList.class);
   digester.addObjectCreate("Collection/ID", java.lang.Long.class);
   digester.addSetNext("Collection/ID", "add" , "java.lang.Object");

   Collection collection = (Collection)digester.parse( new StringReader(xml)
   assertTrue("Should contain 1 instance: size=" + collection.size(),
   assertTrue("Should contain 1: size=" + collection.size() + ",
collection=" + collection, collection.contains(new Long(1)));
At the end of the day, I want this:


To be digested into a Collection of Long wrappers.

But I am of course getting the following exception:

java.lang.InstantiationException: java.lang.Long

because there is no no-arg constructor for long.  I really am hoping I don't
have to create an ObjectCreationFactory, as I was hoping there'd be some
helper class within Digester to assist with primitives as such (such as a

Any help would be appreciated.

Paul Smith 
Lawlex Compliance Solutions
phone: +61 3 9278 1511

View raw message