groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mario Garcia <mario.g...@gmail.com>
Subject Re: Spring Groovy application context and creating @Immutable class beans
Date Mon, 25 Apr 2016 21:37:11 GMT
You're welcome :)
On 25 Apr 2016 20:05, "Rick Venutolo" <rvenutolo@digitalenvoy.net> wrote:

> I had not thought to use that constructor. Thank you!
>
> On Mon, Apr 25, 2016 at 5:01 AM, Mario Garcia <mario.ggar@gmail.com>
> wrote:
>
>> Although I think It should be better to discuss this in the Grails
>> mailing list (they sure have much more experience in Spring+Groovy) I have
>> done a little test in a Grails app with an immutable (@Immutable) bean:
>>
>> package a.b.c
>>
>> @Immutable
>> class Pagination {
>>    Integer max
>> }
>>
>> myBean(a.b.c.Pagination, [max:1001])
>>
>> and it seems to be working.
>> Mario
>>
>> 2016-04-11 22:47 GMT+02:00 Rick Venutolo <rvenutolo@digitalenvoy.net>:
>>
>>> Hi all,
>>>
>>> As a fun learning experience I am attempting to move an application's
>>> Spring configuration from XML to Groovy. I need to create a bean for a
>>> Groovy class that is annotated with @Immutable.
>>>
>>> Let's say my class is this:
>>>
>>> @Immutable
>>> class MyImmutableClass {
>>>     String someString
>>>     String otherString
>>>     String anotherString
>>> }
>>>
>>>
>>> And I attempt to create a bean like so:
>>>
>>> beans {
>>>     myImmutableClass(
>>>             MyImmutableClass,
>>>             someString: 'some',
>>>             otherString: 'other',
>>>             anotherString: 'another'
>>>     )
>>> }
>>>
>>> It fails:
>>> Invalid property 'someString' of bean class [MyImmutableClass]: Bean
>>> property 'someString' is not writable or has an invalid setter method. Does
>>> the parameter type of the setter match the return type of the getter?
>>>
>>> I can do the following, but I then lose the parameter name information
>>> that tells me which fields are set to which values:
>>>
>>> beans {
>>>     myImmutableClass(
>>>             MyImmutableClass,
>>>             'some',
>>>             'other',
>>>             'another'
>>>     )
>>> }
>>>
>>>
>>> I can also remove the @Immutable annotation from the class. But let's
>>> assume this class comes from somewhere else and I cannot modify it.
>>>
>>> So what are my options here that combine not modifying the @Immutable
>>> class and keeping the parameter names? I know I can combine Groovy and XML
>>> configuration and define the bean in XML and then use importBeans in my
>>> Groovy code, but is there something I can do that is purely Groovy?
>>>
>>> I found this issue, which describes my problem:
>>> https://issues.apache.org/jira/browse/GROOVY-7078
>>>
>>> Thanks,
>>> Rick
>>>
>>>
>>>
>>
>

Mime
View raw message