You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by "Stefan Seifert (JIRA)" <ji...@apache.org> on 2015/01/22 23:51:34 UTC

[jira] [Commented] (SLING-4242) Sling Models: make enums injectable from Resource/ValueMap

    [ https://issues.apache.org/jira/browse/SLING-4242?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14288373#comment-14288373 ] 

Stefan Seifert commented on SLING-4242:
---------------------------------------

ah, you are correct - the type mapping does not exist in this generic form, the ValueMapInjector is the only injector which cares more explict about types and mappings. still, other injectors may return string values as well which can be mapped to enums.

so, a generic approach to implement this for all injectors in a central place could be (did not test it myself):
# start in ModelAdapterFactory.injectElement
# if the type of the injectable element that is to be injectes is a enum, pass a type string to the injector and try to resolve the injections as a string.
# if a value could be resolved, try to map it the an enum value and inject it further down the road.

if this works it should be not that much code (but a lot of unit tests should be written/extended to test the enum support in the different scenarios).

> Sling Models: make enums injectable from Resource/ValueMap
> ----------------------------------------------------------
>
>                 Key: SLING-4242
>                 URL: https://issues.apache.org/jira/browse/SLING-4242
>             Project: Sling
>          Issue Type: Improvement
>          Components: Extensions
>    Affects Versions: Sling Models Implementation 1.1.0, Sling Models API 1.1.0
>            Reporter: David Herges
>            Priority: Minor
>              Labels: enum, injection, injectionutils, models
>
> As of Sling Models 1.1.0 it seems to not be possible to inject enum values from Resources and ValueMaps.
> A custom injector could provide that feature. GitHub gist: https://gist.github.com/dherges/5d8f3c6b6821759cfa1c
> Question remains whether it is a good idea to do String-to-Enum-mapping in Sling Models?
> Alternative would be to have ResourceDecorators/ValueMapDecorators that already hold enum values.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)