In very old versions of Groovy, I believe there was a mechanism that tried to be smart for some GPath expressions, working out when the list size was 1 and in that case returning the value instead of the list. This turned out to be a bad idea that was trying to be "too smart", prohibiting certain kinds of processing, e.g. you want the list of 1 to replace the value. We deprecated and swapped out that behavior a long time ago. I tried to find it in the release notes or a Jira issue but I couldn't easily find it.
Of course, with metaprogramming, Groovy lets you add such behavior back if you never want to do the kind of processing I referred to. Cheers, Paul. On Mon, Jun 2, 2025 at 10:32 PM Jochen Theodorou <blackd...@gmx.org> wrote: > > > > On 5/14/25 11:55, Jeemol K S via dev wrote: > [...] > > In *Groovy 2.x*, it was possible to reference elements directly without > > specifying the index, such as: > > > > > > |response.itemResult.itemResultItems.salePrice | > > > > However, in *Groovy 3.x*, the same reference now requires explicit indexing: > > > > |response.itemResult.itemResultItems[0].salePrice | > > > Let me try to rewrite this with more context > > > class Result { > List items > } > class Item { > def price > } > > def item = new Item(price:10) > def result = new Result(items:[item]) > > println result.items.price > > Groovy 2.5, 3.0, 4.0 and 5.0-alpha gives [10] > > > I am afraid I cannot reproduce the problem. Or is this with static > compilation? checking again... needs to be List<Item> but otherwise > works with the static type checker as well in all versions I tested > > bye Jochen