Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-10073

Unable to use custom string representation in GString template

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 2.5.14
    • None
    • Templating
    • None

    Description

      I have a class

      class JsonListAdapter implements List {
          private final List<Object> adaptee;
          private final JsonNode node;
      
          public JsonListAdapter(List<Object> adaptee, JsonNode node) {
              this.adaptee = adaptee;
              this.node = node;
          }
      
          // methods here
      
          @Override
          public String toString() {
              return node.toString();
          }
      }
      

      I'm expecting that it will work like

      var json = "[\"v1\",\"v2\"]";
      var node = parseJson(json);
      var list = toList(node);
      var result = gStringTemplateService.render("${variable}", Map.of("variable", new JsonListAdapter(list, node)));
      
      // both assertions fail for now
      Assertions.assertNotEquals("[v1, v2]", result);
      Assertions.assertEquals(json, result);
      

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              gallyamb Gallyam Biktashev
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated: