cancel
Showing results for 
Search instead for 
Did you mean: 

How to correctly merge maps in spring context using hybris mapMergeDirective

Former Member
0 Kudos

Hi to all, please suggest what I do wrong. In root spring context I have the next declarations

 <util:map id="prefixPriorities" key-type="java.lang.String" value-type="java.lang.Integer">
     <entry key="address_customer" value="101" />
     <entry key="colorenum" value="100" />
 </util:map>

 <bean id="fileOrderComparator" class="de.hybris.platform.acceleratorservices.dataimport.batch.FileOrderComparator">
     <property name="prefixPriority" ref="prefixPriorities"/>
 </bean>

And child spring context is:

 <bean id="capacityEnumMapping" depends-on="prefixPriorities" parent="mapMergeDirective">
     <property name="key" value="capacityenum" />
     <property name="value">
         <value type="java.lang.Integer">
             100
         </value>
     </property>
 </bean>

During starting the server I'm facing the next error

 Cannot convert value of type 'org.springframework.beans.factory.config.TypedStringValue' to required type 'java.lang.Integer' for property 'prefixPriority[capacityenum]': PropertyEditor [org.springframework.beans.propertyeditors.CustomNumberEditor] returned inappropriate value of type 'org.springframework.beans.factory.config.TypedStringValue'

Thanks

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Used the next approach and all works fine. Very strange issue

 <bean depends-on="prefixPriorities" parent="mapMergeDirective">
     <property name="sourceMap">
         <map>
             <entry key="capacityenum" value="100"/>
         </map>
     </property>
 </bean>

Answers (1)

Answers (1)

Former Member
0 Kudos

Have you already tried the following? Not sure this will fix your issue, but the additional type declaration on your value in the child context shouldn't be necessary.

As you've already defined the value type in map prefixPriorities, try simply assigning the value in your child spring context without redeclaring the type of java.lang.Integer:

  <bean id="capacityEnumMapping" depends-on="prefixPriorities" parent="mapMergeDirective">
      <property name="key" value="capacityenum" />
      <property name="value" value="100" />
  </bean>
Former Member
0 Kudos

Right, did it already, the same. Thanks for suggesting.

Former Member
0 Kudos

What I noticed, that value are set to the map correctly. But then before setting the map to the bean for some unknown reasons the map contains wrong values.