Details
-
Bug
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
2.4.3
Description
Cloned from the @EqualsAndHashCode issue to handle the same problem with @ToString as an independent issue.
I have the following class representing a location in Amazon S3. Depending on some inner business logic, I often need to split the object key into a prefix and a file name, so I access them all through the getKey() method; with S3, the only thing that matters is the final concatenated string.
The generated toString method doesn't display properties following the JavaBean conventions, e.g. with explicit getXxx() or isYyy() methods but no field as per normal Groovy conventions for properties with auto getters/setters.
import groovy.transform.* @ToString(includes = ['bucket', 'key'], includeNames = true) class S3ImageLocation { final String bucket final String prefix final String subKey S3ImageLocation(String bucket, String prefix, String subKey) { this.bucket = bucket this.prefix = prefix this.subKey = subKey } S3ImageLocation(String bucket, String subKey) { this(bucket, null, subKey) } String getKey() { prefix ? "$prefix/$subKey" : subKey } } // expected below (current is 'S3ImageLocation(bucket:foo)') assert new S3ImageLocation('foo', 'bar', 'baz').toString() == 'S3ImageLocation(bucket:foo, key:bar/baz)'
Attachments
Issue Links
- is related to
-
GROOVY-7390 @EqualsAndHashCode incorrect when using non-field properties
- Closed