Hi Justin,
I listed the places down below. Do you agree with the other points raised?

On 07 Aug 2014, at 22:05, Justin Edelson <[email protected]> wrote:

> Hi Konrad,
> Where are (a) and (b) implemented in the ModelAdapterFactory for fields?
> 
> Justin
> 
> On Thu, Aug 7, 2014 at 1:30 PM, Konrad Windszus <[email protected]> wrote:
>> Currently in Sling Models we do have support for four different kind of type 
>> conversions
>> 
>> a) from primitive to wrapper and vice-versa (also within arrays), e.g. 
>> Integer to int
>> b) from single item to one item collection (both List and Collection), e.g. 
>> List<Integer> to Integer
>> c) from Adaptable to supported AdapterType
>> d) from subtype to super type
>> 
>> That conversion logic must either be implemented in the Injector itself (if 
>> it does evaluate the type) or the ModelAdapterFactory is taking care of 
>> that. In the latter case the support differs for field and method:
>> - Method injection supports only c), d)
>> - Field injection supports a), b), c) and d)

a) is implemented at 
https://github.com/apache/sling/blob/trunk/bundles/extensions/models/impl/src/main/java/org/apache/sling/models/impl/ModelAdapterFactory.java#L724
-> the actual conversion is done through reflection though I admit

b) is implemented at 
https://github.com/apache/sling/blob/trunk/bundles/extensions/models/impl/src/main/java/org/apache/sling/models/impl/ModelAdapterFactory.java#L651

>> 
>> The support for these conversions differs a lot between the different 
>> injectors.
>> 1) BindingsInjector, checks for type itself, does neither support a), b), c) 
>> nor d)!
>> 2) ChildResource does no type checking, therefore uses the 
>> ModelAdapterFactory for the conversions
>> 3) OSGiService checks for the type itself, does neither support a), b), c) 
>> nor d)!
>> 4) RequestAttribute checks for type itself, does neither support a), b), c) 
>> nor d)!
>> 5) ResourceResolverInjector does no type checking, therefore uses the 
>> ModelAdapterFactory for the conversions
>> 6) ValueMapInjector, checks for type itself, supports a), b), c)
>> 
>> 
>> I have several proposals regarding that:
>> ======
>> - let all injectors support all conversions
>> - let both method and field injection support all conversions
>> - consolidate the code in one place
>> - document the conversions which are supported.
>> 
>> WDYT?
>> Konrad

Reply via email to