Description
It would be useful if DynaBean would have support for "nested dynamic types", like e.g. EMF and SDO have.
Currently simple types (or the content types of indexed or mapped types) must "be a Java language primitive (such as int, a simple object (such as a java.lang.String), or a more complex object whose class is defined either by the Java language". It turns out it wouldn't be very hard at all (I've tried and will attach a patch) to make some minor changes to relax this, and in addition also allow the following usage:
DynaProperty[] adrProps = new DynaProperty[]{ new DynaProperty("zip", Long.class) }; BasicDynaClass adrDynaClass = new BasicDynaClass("Address", adrProps); DynaProperty[] empProps = new DynaProperty[]{ new DynaProperty("address", java.util.Map.class, adrDynaClass), new DynaProperty("subordinate", java.util.List.class, DynaClass.class), new DynaProperty("firstName", String.class), new DynaProperty("lastName", String.class), new DynaProperty("mainAddress", adrDynaClass), new DynaProperty("boss", DynaClass.class) }; BasicDynaClass empDynaClass = new BasicDynaClass("Employee", empProps); empDynaClass.getDynaProperty("boss").setDynaType(empDynaClass); empDynaClass.getDynaProperty("subordinate").setDynaType(empDynaClass); // --- DynaBean address = adrDynaClass.newInstance(); address.set("zip", new Long(9016)); DynaBean subordinate = empDynaClass.newInstance(); subordinate.set("firstName", "Dino"); DynaBean boss = empDynaClass.newInstance(); boss.set("firstName", "Wilma"); DynaBean employee = empDynaClass.newInstance(); employee.set("firstName", "Fred"); employee.set("lastName", "Flintstone"); employee.set("mainAddress", address); employee.set("boss", boss); PropertyUtils.setProperty(employee, "boss.lastName", "Flintstone"); employee.set("address", new HashMap()); PropertyUtils.setProperty(employee, "address(home)", address); employee.set("subordinate", new ArrayList()); ((List)employee.get("subordinate")).add(subordinate);
Attachments
Attachments
Issue Links
- is depended upon by
-
BEANUTILS-406 DynaClassReader to read DynaClass definitions from a "DSL"
- Open