You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Nuno Oliveira <no...@itclinical.com> on 2018/04/04 14:50:49 UTC

Type conversion collection with interface type elements

Hi,

I am having problems populating an action variable Set by request using
struts type conversion if the Set has the element type defined as an
interface.
I have a UserAction-conversion.properties file with the following
configuration using the class implementation:

KeyProperty_roles=id
Element_roles=path.to.class.Roles
CreateIfNull_roles=true

And UserAction has the collection Set<RolesInterface>. Roles obviously
implements RolesInterface.

If the Set element type <RolesInterface> is deleted it works just fine.
Am I doing something wrong or is this not possible?

Thanks


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Fwd: Type conversion collection with interface type elements

Posted by Yasser Zamani <ya...@apache.org>.

On 4/5/2018 6:52 PM, Nuno Oliveira wrote:
> Your fix worked :) and I see why it did not work, thank you.
> 
> Also yes, you are right, it should be Role instead of Roles but it is a
> legacy class and the change implies a lot of fixes. It's on the "to do
> list". 
> 
> Once more, thank you.

You're welcome :) glad to hear this. However, I think it's better that
Struts honor .properties file (where element class has been defined
strictly by user) before the generic parametrics [1]. Could you please
register an issue at [2] with title "conversion fails when generic type
is an interface" then paste these emails contents in it's description.

Thanks for your report!

[1]
github.com/apache/struts/blob/05829e3faadd15cfa67eb234cd1775f2b98918cb/core/src/main/java/com/opensymphony/xwork2/conversion/impl/DefaultObjectTypeDeterminer.java#L100
[2] issues.apache.org/jira/projects/WW/

Re: Fwd: Type conversion collection with interface type elements

Posted by Nuno Oliveira <no...@itclinical.com>.
Your fix worked :) and I see why it did not work, thank you.

Also yes, you are right, it should be Role instead of Roles but it is a
legacy class and the change implies a lot of fixes. It's on the "to do
list". 

Once more, thank you.




On Qui, 2018-04-05 at 13:13 +0000, Yasser Zamani wrote:
> [copy with removed links to avoid detection as spam]
> 
> 
> -------- Forwarded Message --------
> Subject: Re: Type conversion collection with interface type elements
> Date: Thu, 5 Apr 2018 13:02:01 +0000
> From: Yasser Zamani <ya...@apache.org>
> Reply-To: Struts Users Mailing List <us...@struts.apache.org>
> To: user@struts.apache.org <us...@struts.apache.org>
> 
> 
> 
> On 4/4/2018 7:20 PM, Nuno Oliveira wrote:
> > Hi,
> > 
> > I am having problems populating an action variable Set by request using
> > struts type conversion if the Set has the element type defined as an
> > interface.
> > I have a UserAction-conversion.properties file with the following
> > configuration using the class implementation:
> > 
> > KeyProperty_roles=id
> > Element_roles=path.to.class.Roles
> > CreateIfNull_roles=true
> > 
> > And UserAction has the collection Set<RolesInterface>. Roles obviously
> > implements RolesInterface.
> > 
> > If the Set element type <RolesInterface> is deleted it works just fine.
> > Am I doing something wrong or is this not possible?
> 
> I reproduced it and seems it's because it tries to instantiate a new
> element but the interface cannot being instantiated. Please see [1] to
> know why it tries to instantiate interface instead of class.
> 
> Annotating the getRoles or setRoles method with @Element(value =
> path.to.class.Roles.class) may fix this issue. (shouldn't it be
> path.to.class.Role instead? it seems Roles is a list not element)
> 
> Regards.
> 
> [1]
> github.com/apache/struts/blob/05829e3faadd15cfa67eb234cd1775f2b98918cb/core/src/main/java/com/opensymphony/xwork2/conversion/impl/DefaultObjectTypeDeterminer.java#L100
> 
> > 
> > Thanks
> > 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Fwd: Type conversion collection with interface type elements

Posted by Yasser Zamani <ya...@apache.org>.
[copy with removed links to avoid detection as spam]


-------- Forwarded Message --------
Subject: Re: Type conversion collection with interface type elements
Date: Thu, 5 Apr 2018 13:02:01 +0000
From: Yasser Zamani <ya...@apache.org>
Reply-To: Struts Users Mailing List <us...@struts.apache.org>
To: user@struts.apache.org <us...@struts.apache.org>



On 4/4/2018 7:20 PM, Nuno Oliveira wrote:
> Hi,
> 
> I am having problems populating an action variable Set by request using
> struts type conversion if the Set has the element type defined as an
> interface.
> I have a UserAction-conversion.properties file with the following
> configuration using the class implementation:
> 
> KeyProperty_roles=id
> Element_roles=path.to.class.Roles
> CreateIfNull_roles=true
> 
> And UserAction has the collection Set<RolesInterface>. Roles obviously
> implements RolesInterface.
> 
> If the Set element type <RolesInterface> is deleted it works just fine.
> Am I doing something wrong or is this not possible?

I reproduced it and seems it's because it tries to instantiate a new
element but the interface cannot being instantiated. Please see [1] to
know why it tries to instantiate interface instead of class.

Annotating the getRoles or setRoles method with @Element(value =
path.to.class.Roles.class) may fix this issue. (shouldn't it be
path.to.class.Role instead? it seems Roles is a list not element)

Regards.

[1]
github.com/apache/struts/blob/05829e3faadd15cfa67eb234cd1775f2b98918cb/core/src/main/java/com/opensymphony/xwork2/conversion/impl/DefaultObjectTypeDeterminer.java#L100

> 
> Thanks
> 

Re: Type conversion collection with interface type elements

Posted by Yasser Zamani <ya...@apache.org>.

On 4/4/2018 7:20 PM, Nuno Oliveira wrote:
> Hi,
> 
> I am having problems populating an action variable Set by request using
> struts type conversion if the Set has the element type defined as an
> interface.
> I have a UserAction-conversion.properties file with the following
> configuration using the class implementation:
> 
> KeyProperty_roles=id
> Element_roles=path.to.class.Roles
> CreateIfNull_roles=true
> 
> And UserAction has the collection Set<RolesInterface>. Roles obviously
> implements RolesInterface.
> 
> If the Set element type <RolesInterface> is deleted it works just fine.
> Am I doing something wrong or is this not possible?

I reproduced it and seems it's because it tries to instantiate a new
element but the interface cannot being instantiated. Please see [1] to
know why it tries to instantiate interface instead of class.

Annotating the getRoles or setRoles method with @Element(value =
path.to.class.Roles.class) may fix this issue. (shouldn't it be
path.to.class.Role instead? it seems Roles is a list not element)

Regards.

[1]
https://github.com/apache/struts/blob/05829e3faadd15cfa67eb234cd1775f2b98918cb/core/src/main/java/com/opensymphony/xwork2/conversion/impl/DefaultObjectTypeDeterminer.java#L100

> 
> Thanks
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org