ws-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oliver Archner <oliver.arch...@bayceer.uni-bayreuth.de>
Subject Dynamic proxy returns List<Object[]> instead of List<List<Integer>>
Date Fri, 16 Nov 2012 10:22:57 GMT
Hello,

the concept of dynamic proxies looks great and i decided to give it a 
try with the following interface and implementation:

public interface Handler {
         List<Map<String, String>> getMap(Integer id);
         List<List<Integer>> getList(Integer a);
}

public class HandlerImpl implements Handler {
     @Override
     public List<Map<String,String>> getMap(Integer id) {
         List<Map<String,String>> l = new ArrayList<Map<String,String>>(3);

         Map<String,String> r = new Hashtable<String, String>(2);
         r.put("Sample 1", String.valueOf(0));
         r.put("Sample 2", String.valueOf(299));
         l.add(r);

         r = new Hashtable<String, String>(2);
         r.put("Sample 1", String.valueOf(0));
         r.put("Sample 2", String.valueOf(299));
         l.add(r);

         r = new Hashtable<String, String>(2);
         r.put("Sample 1", String.valueOf(0));
         r.put("Sample 2", String.valueOf(299));
         l.add(r);
         return l;
     }

     @Override
     public List<List<Integer>> getList(Integer i) {
         List<List<Integer>> l = new ArrayList<List<Integer>>(1);
         List<Integer> r = new ArrayList<Integer>(2);
         r.add(Integer.valueOf(20));
         r.add(Integer.valueOf(10));
         l.add(r);
         return l;
     }

My test for method getMap runs without errors and without any casting:

@Test A
     public void getMapTypeFactory() {
         try {
             ClientFactory factory = new ClientFactory(client);
             Handler zm = (Handler) 
factory.newInstance(ClassLoader.getSystemClassLoader(), 
Handler.class,"Handler");
             List<Map<String,String>> o = zm.getMap(1);
             for (Map<String, String> m : o) {
                 System.out.print("|");
                 System.out.print(m);
             }
         } catch (Exception e) {
             fail(e.getMessage());
         }
     }

I decided to write a test for the getList method as well:

@Test B
     public void getListTypeFactory() {
         ClientFactory factory = new ClientFactory(client);
         Handler zm = (Handler) 
factory.newInstance(ClassLoader.getSystemClassLoader(), 
Handler.class,"Handler");
                 List<List<Integer>> o = zm.getList(1);
                 for (List<Integer> m : o) {
                    System.out.print("|");
                    System.out.print(m);
                 }
    }

It throws a casting exception because zm.getList(1) returns: 
List<Object[]> and not as expected: List<List<Integer>>.
I already know that there is a workaround for this problem, but i would 
prefer the usage of factories and the provided type converters.
Can someone explain me why test case B fails and A not ? Is it a problem 
because of the nested types ?

Oliver







---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ws.apache.org
For additional commands, e-mail: dev-help@ws.apache.org


Mime
View raw message