[ https://issues.apache.org/jira/browse/GROOVY-10073?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17340176#comment-17340176 ]
Gallyam Biktashev edited comment on GROOVY-10073 at 5/6/21, 12:09 PM: ---------------------------------------------------------------------- Thank you for reply! It's intentionally implements {{List}}, because users (templates are written by app users) need to operate with such variables as normal groovy list, with all available methods, such as {{grep}}/{{collect}}/etc. And when rendered, the result should be valid json In future I don't want to reflect changes in List API manually, so it have to implement List was (Author: gallyamb): Thank you for reply!t It's intentionally implements \{{List}}, because users (templates are written by app users) need to operate with such variables as normal groovy list, with all available methods, such as \{{grep}}/\{{collect}}/etc. And when rendered, the result should be valid json In future I don't want to reflect changes in List API manually, so it have to implement List > Unable to use custom string representation in GString template > -------------------------------------------------------------- > > Key: GROOVY-10073 > URL: https://issues.apache.org/jira/browse/GROOVY-10073 > Project: Groovy > Issue Type: Bug > Components: Templating > Affects Versions: 2.5.14 > Reporter: Gallyam Biktashev > Priority: Major > > I have a class > {code:java} > 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(); > } > } > {code} > I'm expecting that it will work like > {code:java} > 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); > {code} -- This message was sent by Atlassian Jira (v8.3.4#803005)