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

Andrei Shakirin commented on SYNCOPE-246:
-----------------------------------------

Hi Francesco,

I try to explain the issue: originally we have a problem because JAXB and 
Spring MVC work differently with list members of java beans:
- Spring MVC uses normal setter to set a list value
- JAXB uses only getter to return the list and custom code adds / removes 
elements.

The problem was that if we leave setter for lists in bean, JAXB tries to set 
the same list object through the setter and code in setter clears list content, 
so list will be empty:
    public void setEntitlements(final List<String> entitlements) {
            this.entitlements.clear();
            if (entitlements != null && !entitlements.isEmpty()) {
                this.entitlements.addAll(entitlements);
            }
    }

Therefore Christian adds workaround that checks if list object is the same 
(JAXB case) and do nothing in that case:
    public void setEntitlements(final List<String> entitlements) {
        if (this.entitlements != entitlements) {
            this.entitlements.clear();
            if (entitlements != null && !entitlements.isEmpty()) {
                this.entitlements.addAll(entitlements);
            }
        }
    }

But actually, clean final solution will be to remove list setters from TO 
objects at all. That is possible only when we do not support Spring MVC REST 
anymore.

Regards,
Andrei.
 
                
> Remove collection setters in transfer objects for JAXB marshalling
> ------------------------------------------------------------------
>
>                 Key: SYNCOPE-246
>                 URL: https://issues.apache.org/jira/browse/SYNCOPE-246
>             Project: Syncope
>          Issue Type: Sub-task
>          Components: core
>    Affects Versions: 1.1.0
>         Environment: CXF branch
>            Reporter: Andrei Shakirin
>            Assignee: Christian Schneider
>             Fix For: 1.2.0
>
>
> XML payload will be marshaled/unmarshaled using JAXB by migration to CXF Rest 
> frontend.
> JAXB works with collections in a little bit different way as Spring Rest 
> marshaling.
> JAXB uses only getter for the list (assumes that list is initialized due 
> object creation) and adds elements into the list obtained by getter by 
> unmarshaling. It doesn't need setter at all.
> The problem is that actual implementation of transfer objects doesn't work 
> with JAXB. 
> If TO provide setter for collection, JAXB gets the list, adds the elements 
> and additionally calls setter for this list. As far as setter logic cleans 
> the TO collection, the result collection is always empty.
> Solution is remove setters for collections in TOs by migration on CXF Rest.
> I find it also better from security and encapsulation aspects.
> Regards,
> Andrei.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to