Uploaded image for project: 'Struts 2'
  1. Struts 2
  2. WW-3397

IncludeProperties within Json plugin are not handled properly with patterns including arrays

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Duplicate
    • 2.1.8
    • 2.2.3
    • Other
    • None

    Description

      In order to repeat the error (on version struts2-json-plugin-2.1.8 ) it's enough to use a regexp pattern like this(in general the use of array [\d+] should be not at the first level, but deeper):
      <param name="includeProperties">
      operatorsgrid\.items[\d+]\.name
      </param>
      This pattern aims to extract a name property given this structure:
      1)The Action has a getter:
      OperatorsDTO getOperatorsgrid(){};
      2)OperatorsDTO is defined as:
      class OperatorsDTO{
      public List<Operators> getItems(){}
      }
      3)Each Operator bean has (among others) a getName() method returning a String

      With this configuration, the JSON created will be empty (just {"operatorsgrid":{}} ).
      The problem has to be found in the method setIncludeProperties() of org.apache.struts2.json.JSONResult class
      Given the above regexp, this method produces this list of patterns:
      [operatorsgrid, opera, operatorsgrid\.items[\d+], operatorsgrid\.items[\d+]\.name]
      Clearly there is the lack of one fundamental item: operatorsgrid\.items . Without this, the property items won't be explored. moreover there is another item "opera" which apparently is meaningless.
      The error is at line 160:
      this.includeProperties.add(Pattern.compile(patternExpr.substring(0, patternPiece
      .lastIndexOf("
      ["))));
      patternPiece is already a substring of patternExpr (line 151) so if this lines aims to add a new pattern which just excludes the las [\d+], it should be changed to:
      this.includeProperties.add(Pattern.compile(patternExpr.substring(0, patternExpr
      .lastIndexOf("
      ["))));
      Given this, the new pattern set becomes:
      [operatorsgrid, operatorsgrid\.items, operatorsgrid\.items[\d+], operatorsgrid\.items[\d+]\.name]
      now the "opera" is vanished while we have operatorsgrid\.items which allows to dig into Operators bean.

      Attachments

        Activity

          People

            jafl John Lindal
            pluttero Paolo Lutterotti
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: