Hi!
Am I doing something wrong, or have I stumbled across something that has not
yet been implemented?
My understanding is that I should be able to register a rule for an embedded
object. Example:
public static class MyObject {
enum MyEnum { ONE, TWO, THREE };
public MyObject(){}
public MyEnum getValue() {
return MyEnum.ONE;
}
}
public static class MyDTO extends DTO {
public String value;
}
MyObject o = new MyObject();
Adapter ad = converter.getAdapter().rule( String.class,
MyObject.MyEnum.class, v -> MyObject.MyEnum.valueOf( v ), v -> v.name() );
MyDTO my = ad.convert( o ).to( MyDTO.class );
However, this throws an Exception:
org.osgi.service.converter.ConversionException: Cannot create DTO class MyDTO
at
org.apache.felix.converter.impl.ConvertingImpl.convertToDTO(ConvertingImpl.java:240)
at
org.apache.felix.converter.impl.ConvertingImpl.to(ConvertingImpl.java:136)
at
org.apache.felix.converter.impl.AdapterImpl$ConvertingWrapper.to(AdapterImpl.java:145)
at
org.apache.felix.converter.impl.AdapterImpl$ConvertingWrapper.to(AdapterImpl.java:145)
at
org.apache.felix.converter.impl.AdapterImpl$ConvertingWrapper.to(AdapterImpl.java:119)
... plenty more
Caused by: java.lang.IllegalArgumentException: Can not set java.lang.String
field MyDTO.value to MyObject$MyEnum
at
sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:167)
at
sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:171)
at
sun.reflect.UnsafeObjectFieldAccessorImpl.set(UnsafeObjectFieldAccessorImpl.java:81)
at java.lang.reflect.Field.set(Field.java:764)
at
org.apache.felix.converter.impl.ConvertingImpl.convertToDTO(ConvertingImpl.java:233)
... 39 more
Looks like the rule is not getting applied. Indeed, when I step through the
code, I cannot see any place where the rule is taken into account.
Cheers,
=David