felix-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Leangen <o...@leangen.net>
Subject Re: [Converter] Embedded Types
Date Mon, 15 Aug 2016 12:20:41 GMT

Hey David B.,

I updated the code. How should I submit the patch? I did not see a JIRA component for this.


Cheers,
=David




> On Aug 13, 2016, at 4:19 PM, David Leangen <osgi@leangen.net> wrote:
> 
> 
> Thanks, David B! I take it that my assumption is correct, then.
> 
> Will look into this as soon as I can.
> 
> 
> Cheers,
> =David
> 
> 
>> On Aug 12, 2016, at 6:09 PM, David Bosschaert <david.bosschaert@gmail.com>
wrote:
>> 
>> Hi David,
>> 
>> The rules are applied in AdapterImpl.ConvertingWrapper.to() where they are
>> looked up in a map of class rules.
>> 
>> If you find that the current implementation does not support the case you
>> have above, it would be great if you could come up with a patch :)
>> 
>> Cheers,
>> 
>> David
>> 
>> On 12 August 2016 at 04:11, David Leangen <osgi@leangen.net> wrote:
>> 
>>> 
>>> 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
>>> 
>>> 
>>> 
> 


Mime
View raw message