|
Hello,
I've created attached example. I'm using following xml
<order>
<header>
<info>test</info>
</header>
<items>
<item-a>
<a>test-a</a>
</item-a>
<item-b>
<b>test-b</b>
</item-b>
<item-v>
<c>test-v</c>
</item-v>
</items>
</order>
This should be mapped/bind into following classes:
public class Order {
public OrderHeader getHeader() {
return header;
}
public void setHeader(OrderHeader header) {
this.header = header;
}
public List<Item> getItems() {
return items;
}
public void setItems(List<Item> items) {
this.items = items;
}
private OrderHeader header;
private List<Item> items;
}
public class OrderHeader {
String info;
public String getInfo() {
return info;
}
public void setInfo(String info) {
this.info = info;
}
}
public class Item {
public enum ItemType { A, B, V };
private ItemType itemType;
private String a;
private String b;
private String c;
public void setA(String a) {
this.a = a;
}
public void setB(String b) {
this.b = b;
}
public void setC(String c) {
this.c = c;
}
public void setItemType(ItemType itemType) {
this.itemType = itemType;
}
public String getA() {
return a;
}
public String getB() {
return b;
}
public String getC() {
return c;
}
public ItemType getItemType() {
return itemType;
}
}
Therefore I'm using following configuration:
<smooks-resource-list xmlns="http://www.milyn.org/xsd/smooks-1.1.xsd"
xmlns:core="http://www.milyn.org/xsd/smooks/smooks-core-1.4.xsd"
xmlns:jb="http://www.milyn.org/xsd/smooks/javabean-1.4.xsd">
<jb:bean beanId="Order" class="smooksenumtest.Order" createOnElement="order">
<jb:wiring property="items" beanIdRef="items" />
</jb:bean>
<jb:bean beanId="items" class="java.util.ArrayList" createOnElement="items">
<jb:wiring beanType="smooksenumtest.Item" />
</jb:bean>
<jb:bean beanId="a" class="smooksenumtest.Item" createOnElement="item-a">
<jb:value property="a" data="item-a/a" />
<!-- Using a non existing element to obtain default-value -->
<jb:value property="itemType" data="item-a/dummy" decoder="Enum" default="A" >
<jb:decodeParam name="enumType">smooksenumtest.Item#ItemType</jb:decodeParam>
<jb:decodeParam name="A">A</jb:decodeParam>
</jb:value>
</jb:bean>
</smooks-resource-list>
This configuration generates following exception:
Exception in thread "main" org.milyn.cdr.SmooksConfigurationException: Invalid Enum decoder configuration. Failed to resolve 'org.packacge.Item.ItemType' as a Java Enum Class.
And depends on a ClassNotFound-Exception from the EnumDecoder. The class exists. If I create a "standalone" java enum everything works fine.
Smooks is just unable to find the enum inside the Item class.
|
The Reflection API uses $ instead of . or # for inner classes/enums.
Solution:
using smooksenumtest.Item$ItemType inside the smooks-configuration.