title: Jenkins Pipeline Custom Class - inconsistent handling of toString() method
body: <p>I have a Jenkins Pipeline script in which I have created a custom class to represent an AWS AMI. This class extends java.lang.Object and overrides java.lang.Object.toString(). The obvious intention being that I could refer to the object directly when creating strings and get a useful string representing the object.</p>
  
  <p>Unfortunately, jenkins-pipeline doesn't quite see it that way. It is happy to respect requests for the toString() method directly, but without toString, my println/echo steps are silently dropped or produce inconsistent output.</p>
  
  <p>See the snippet below for what I am talking about, and how a different class, e.g. Map works precisely as intended.</p>
  
  <p>Additionally, the code works <strong>perfectly</strong> in the Jenkins script console. But in a jenkins-pipeline job, even with Sandbox disabled; it does not.</p>
  
  <pre><code>public class Ami implements Serializable {
    private String nodetype
    private String id
    private String created
    private boolean related
    private boolean rebuild
  
    Ami(
      String nodetype,
      String id       = 'None',
      String created  = 'None',
      boolean related = false,
      boolean rebuild = false
    ) {
      this.nodetype = nodetype
      this.id       = id
      this.created  = created
      this.related  = related
      this.rebuild  = rebuild
    }
  
    @Override
    public String toString() {
      this.nodetype + '/' + this.id
    }
  }
  
  Ami newami = new Ami('foo')
  println("Concat toString: " + newami.toString())
  println("Concat normal: " + newami)
  println("Templated toString: ${newami.toString()}")
  println("Templated normal: ${newami}")
  
  Map testmap = [:]
  testmap = [foo: "bar", snizz: 'snooch']
  println("Concat toString: " + testmap.toString())
  println("Concat normal: " + testmap)
  println("Templated toString: ${testmap.toString()}")
  println("Templated normal: ${testmap}")
  </code></pre>
  
  <p>Script Console Output (as expected):</p>
  
  <pre><code>Concat toString: foo/None
  Concat normal: foo/None
  Templated toString: foo/None
  Templated normal: foo/None
  Concat toString: [foo:bar, snizz:snooch]
  Concat normal: [foo:bar, snizz:snooch]
  Templated toString: [foo:bar, snizz:snooch]
  Templated normal: [foo:bar, snizz:snooch]
  </code></pre>
  
  <p>Jenkins Pipeline (Sandbox Disabled) Output (completely unexpected):</p>
  
  <pre><code>[Pipeline] echo
  Concat toString: foo/None
  [Pipeline] echo
  foo/None
  [Pipeline] echo
  Templated toString: foo/None
  [Pipeline] echo
  Concat toString: [foo:bar, snizz:snooch]
  [Pipeline] echo
  Concat normal: [foo:bar, snizz:snooch]
  [Pipeline] echo
  Templated toString: [foo:bar, snizz:snooch]
  [Pipeline] echo
  Templated normal: [foo:bar, snizz:snooch]
  [Pipeline] End of Pipeline
  Finished: SUCCESS
  </code></pre>