Spring Roo
  1. Spring Roo
  2. ROO-1253

@RooToString - Add ability to ignore properties

    Details

    • Type: Improvement Improvement
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Complete
    • Affects Version/s: 1.1.0.M2
    • Fix Version/s: 1.1.0.RC1
    • Component/s: GENERAL OBJECTS
    • Labels:
      None

      Description

      I really think this feature is needed and it can be accomplished very easily without interfering with the current functionality.

      Basically, I see 3 approaches:

      1. An optional exclusion parameter to the annotation.

      @RooToString(ignoreProperties={"pets"})
      class Owner
      

      2. An additional annotation similar to @JsonIgnoreProperties
      (org.codehaus.jackson.annotate.JsonIgnoreProperties). This is probably too redundant for its purpose as 1. accomplishes the same thing and would not require an additional tag.

      @RooToString
      @RooToStringIgnoreProperties({"pets"})
      class Owner
      

      3. An additional annotation similar to @JsonIgnore
      (org.codehaus.jackson.annotate.JsonIgnore) This annotation would be placed above any property you want ignored.

      @RooToString
      class Owner {
      	String name
      
      	@RooToStringIgnore
      	Set<Pet> pets
      }
      

        Issue Links

          Activity

          Hide
          Jacek Juraszek added a comment -

          I think that first and second approach is sufficent

          Show
          Jacek Juraszek added a comment - I think that first and second approach is sufficent
          Hide
          Alan Stewart added a comment -

          Approach 1 above implemented but using "ignoreFields" attribute. Added in Git ID 791480cb6207f8eee11aefe6c68372730710a1dc

          Show
          Alan Stewart added a comment - Approach 1 above implemented but using "ignoreFields" attribute. Added in Git ID 791480cb6207f8eee11aefe6c68372730710a1dc
          Hide
          Alan Stewart added a comment -

          'ignoreFields' changed to 'excludeFields' in Git ID d620f7d321f202a4454f67a1efe994f58e155384

          Show
          Alan Stewart added a comment - 'ignoreFields' changed to 'excludeFields' in Git ID d620f7d321f202a4454f67a1efe994f58e155384
          Hide
          Milan Agatonovic added a comment -

          Hi,
          i am trying to figure out how excludeFields work.
          My aim is to exclude field1 and field2 from toString method and leave only filed3
          I am using 1.1.0.RELEASE build.

          In MyObject domain class I have:
          @Entity
          @RooJavaBean
          @RooToString(excludeFields=

          {"field1", "field2"}

          )
          @Table(name = "myobject")
          public class MyObject

          but MyObject_Roo_ToString MyObject.toString() method is not updated, namely it contains:
          public String MyObject.toString()

          { StringBuilder sb = new StringBuilder(); sb.append("Id: ").append(getId()).append(", "); sb.append("Version: ").append(getVersion()).append(", "); sb.append("Field1: ").append(getField1()).append(", "); sb.append("Field2: ").append(getField2()).append(", "); sb.append("Field3: ").append(getField3()).append(", "); return sb.toString(); }

          and whatever change i make in excludeFields doesn't get picked up.
          Any idea, what I am doing wrong?
          thanks,
          Milan

          Show
          Milan Agatonovic added a comment - Hi, i am trying to figure out how excludeFields work. My aim is to exclude field1 and field2 from toString method and leave only filed3 I am using 1.1.0.RELEASE build. In MyObject domain class I have: @Entity @RooJavaBean @RooToString(excludeFields= {"field1", "field2"} ) @Table(name = "myobject") public class MyObject but MyObject_Roo_ToString MyObject.toString() method is not updated, namely it contains: public String MyObject.toString() { StringBuilder sb = new StringBuilder(); sb.append("Id: ").append(getId()).append(", "); sb.append("Version: ").append(getVersion()).append(", "); sb.append("Field1: ").append(getField1()).append(", "); sb.append("Field2: ").append(getField2()).append(", "); sb.append("Field3: ").append(getField3()).append(", "); return sb.toString(); } and whatever change i make in excludeFields doesn't get picked up. Any idea, what I am doing wrong? thanks, Milan
          Hide
          chris marx added a comment -

          I used your code exactly, minus the line breaks, working for me in Roo 1.2.2.RELEASE [rev 7d75659]
          The string builder now reads:

          return new ReflectionToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).setExcludeFieldNames("excludedField1", "excludedField2", etc...)

          Show
          chris marx added a comment - I used your code exactly, minus the line breaks, working for me in Roo 1.2.2.RELEASE [rev 7d75659] The string builder now reads: return new ReflectionToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).setExcludeFieldNames("excludedField1", "excludedField2", etc...)

            People

            • Assignee:
              Alan Stewart
              Reporter:
              Scott Murphy
            • Votes:
              1 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: