[ 
https://issues.apache.org/jira/browse/GROOVY-10073?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17340153#comment-17340153
 ] 

Paul King edited comment on GROOVY-10073 at 5/6/21, 11:33 AM:
--------------------------------------------------------------

I believe this is unrelated to GROOVY-2599 but instead is related to 
GROOVY-9003/GROOVY-4653. The workaround would be to not implement List. You 
might instead have a {{toList()}} or {{asList()}} method on the adapter and 
possibly obtain the rendering you want and other functionality you need.


was (Author: paulk):
I believe this is unrelated to GROOVY-2599 but instead is related to 
GROOVY-9003/GROOVY-4653.

> 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)

Reply via email to