Skip to content

Respect 'merge' attribute of <map> and <list> elements in conjunction with nested property paths [SPR-9552] #14186

Closed

Description

@spring-projects-issues

Matt Wuertz opened SPR-9552 and commented

I work on the Kuali Rice project. When I try to use a map merge with nested properties, it doesn't function correctly. For example:

<bean id="testNestedMap" class="SomeClass">
  <property name="reference1">
    <bean class="SomeClass">
      <property name="map1">
        <map>
          <entry key="keyQ" value="Q"/>
        </map>
      </property>
    </bean>
  </property>
</bean>

<bean parent="testNestedMap">
  <property name="reference1.map1">
    <map merge="true">
      <entry key="keyC" value="C"/>
    </map>
  </property>
</bean>

My hope is to get X and C in the child map. When I do this, however, all I get is C. I have asked for guidance on the forums but did have any responses, which leads me to believe that this is a bug. Please let me know if there is any additional information I can provide.

I placed the priority as Major because I don't have a workaround for this.


Affects: 3.1 GA

Issue Links:

0 votes, 8 watchers

Activity

  1. spring-projects-issues commented on Sep 6, 2012

    @spring-projects-issues
    CollaboratorAuthor

    Matt Wuertz commented

    A note from another team member:

    "I found out that merging of nested lists does not work as well. For example:

      <bean id="testListMerging1" class="org.kuali.rice.krad.uif.UifTestBeanObject">
        <property name="reference1">
          <bean class="org.kuali.rice.krad.uif.UifTestBeanObject">
            <property name="list1">
              <list>
                <value>val1</value>
                <value>val2</value>
              </list>
            </property>
          </bean>
        </property>
      </bean>
    
      <bean id="testListMerging2" parent="testListMerging1">
        <property name="reference1.list1">
          <list merge="true">
            <value>val3</value>
            <value>val4</value>
          </list>
        </property>
      </bean>

    I would expect reference1.list to have 4 items, but it only has the two items val3 and val4. I think the issue is when property values are merged between the child and parent definitions, they only merge properties with the same name (do not consider nested). This is the only place I found where merging was considered."

    Is this something you're planning to add? If so, which version do you anticipate releasing it?

  2. spring-projects-issues commented on Jan 6, 2013

    @spring-projects-issues
    CollaboratorAuthor

    Jerry Neal commented

    Hi,

    We were wondering if there has been any work done on this or if the task is scheduled? This seems like a big issue with the framework. Not being able to use nested properties with merging means you have to copy the entire nested bean from a parent in order to add to a property.

    thanks,
    Jerry

  3. spring-projects-issues commented on Jan 7, 2013

    @spring-projects-issues
    CollaboratorAuthor

    Chris Beams commented

    Hi Matt, Jerry,

    I've just reproduced this problem, as demonstrated in the SPR-9552 branch, and specifically with commit f43d12c663. While it's arguable whether this issue is a bug or an improvement request, I've marked it as an improvement, as there's nothing wrong with existing functionality and it was never specifically documented that merge should work with nested property paths. I've marked this issue as pull-request-encouraged to let contributors know that this is a relatively straightforward and discrete issue that we'd love to have implemented, but may not have time to get to immediately.

    Thanks!

  4. spring-projects-issues commented on Jan 7, 2013

    @spring-projects-issues
    CollaboratorAuthor

    Jerry Neal commented

    Hi Chris,

    Thank you so much for taking a look at this. It would be a good improvement making nested properties more powerful.

    thanks,
    Jerry

  5. spring-projects-issues commented on Mar 3, 2014

    @spring-projects-issues
    CollaboratorAuthor

    Chris Baldwin commented

    I did some digging and found that during the bean merge process the parent bean would have property values that contained BeanDefinition objects for all the nested beans. The child bean would have a property with the nested name (e.g. beanA.beanB.propertyName). When it came time to find the nested property it would be done by a simple name match which would fail to match any of the properties in the parent bean.

    I have modified MutablePropertyValues to recognize the nested property name of the child property and to walk through the chain of nested beans to locate the property and add or merge as appropriate.

    I have created a JUnit test case based on Chris Beams earlier work.

    The proposed changes can be viewed on my SPR-9552 branch.

  6. spring-projects-issues commented on Mar 4, 2014

    @spring-projects-issues
    CollaboratorAuthor

    Chris Baldwin commented

    There is now a pull request for the changes.

  7. spring-projects-issues commented on Feb 1, 2016

    @spring-projects-issues
    CollaboratorAuthor

    Juergen Hoeller commented

    At this point, I'm inclined to leave things as-is with respect to XML collection merging, since it only matters in combination with a feature of decreasing popularity: parent bean definitions. If there's a strong need for this appear in our XML configuration story in 2016 still, feel free to comment on this issue. If we don't hear about strong use cases in time for 4.3, we'll close the ticket for good.

    Juergen

  8. added
    status: declined
    type: enhancement
    on Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

status: declinedtype: enhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions