Uploaded image for project: 'Sling'
  1. Sling
  2. SLING-3674

Array of wrappers to primitives conversion in Sling Models

    XMLWordPrintableJSON

Details

    Description

      Problem is related with: https://issues.apache.org/jira/browse/SLING-3547

      Suppose that I have:

      @Inject
      private int[] scores;

      @Inject
      private Integer[] scores;

      For first declaration injection does not work, because in my environment ValueMap contains array of wrapped integers and type cast to array of primitives cannot be done. I noticed an exception:

      27 [main] ERROR org.apache.sling.models.impl.ModelAdapterFactory - unable to create object
      java.lang.ClassCastException: [I cannot be cast to [Ljava.lang.Object;
      at org.apache.sling.api.wrappers.ValueMapDecorator.convertToArray(ValueMapDecorator.java:100)

      Second declaration seems to work but how to apply default value for it? According to Sling Models documentation, example with default value for array of integers currently it is not possible to get it working. Same error as for first declaration.

      I wrote unit test for it. I hope, useful for reproducing problem, see attachments.

      Attachments

        1. ArrayPrimitivesModel.java
          1 kB
          Krystian Panek
        2. ResourceModelClassesTest.java
          7 kB
          Krystian Panek

        Activity

          People

            justinedelson Justin Edelson
            kpanek Krystian Panek
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: