Announcement Announcement Module
Collapse
No announcement yet.
Map Merge with Nested Properties Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Map Merge with Nested Properties

    I can find plenty of examples for doing something like this:

    Code:
    <bean id="myTestBean" class="SomeClass">
      <property name="map1">
        <map>
          <entry key="keyA" value="A"/>
          <entry key="keyB" value="B"/>
        </map>
      </property>
    </bean>
    
    <bean parent="myTestBean">
      <property name="map1">
        <map merge="true">
          <entry key="keyC" value="C"/>
        </map>
      </property>
    </bean>
    That's all well and good, yielding A, B and C in the child map. But what I'd like to be able to do is this:

    Code:
    <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. Are there limitations around merging with nested properties? My best attempt at getting around this was to put an id on the nested bean in testNestedMap and reference it directly like this:

    Code:
    <bean id="testNestedMap" class="SomeClass">
      <property name="reference1">
        <bean id="testNestedMapForReference1" class="SomeClass">
          <property name="map1">
            <map>
              <entry key="keyQ" value="Q"/>
            </map>
          </property>
        </bean>
      </property>
    </bean>
    
    <bean parent="testNestedMap">
      <property name="reference1">
        <bean parent="testNestedMapForReference1" class="SomeClass">
          <property name="map1">
            <map merge="true">
              <entry key="keyX" value="true"/>
            </map>
          </property>
        </bean>
      </property>
    </bean>
    That yields Q and X in the child map. But I really don't want to do that; in fact, I'm not sure we could take that approach even if I liked it.
Working...
X