jeudi 5 mars 2015

I have to populate a web service with billing address data, and for the state/country it requires special types to populate the request. I only have Strings of states/countries available, so I'm looking to map a string of states/countries that I have to these special types. I've created an Enum class with HashMaps with getters to retrieve the pairs from one another, and am using Spring injection to populate these maps. I'm running into the following issue though when I attempt to deploy my code.



SEVERE: Exception sending context initialized event to listener instance of class de.hybris.platform.spring.HybrisContextLoaderListener
org.springframework.beans.FatalBeanException: Context hybris Global Context Factory couldn't be created correctly due to, Error creating bean with name 'EnumUtil' defined in class path resource [payment3dsi-spring.xml]: Cannot create inner bean 'util:map#4b13c655' of type [org.springframework.beans.factory.config.MapFactoryBean] while setting bean property 'stateCodes'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'util:map#4b13c655': Error converting typed String value for bean property 'sourceMap' with key [TypedStringValue: value [US-IL], target type [class java.lang.String]]; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert value of type 'java.lang.String' to required type 'com.gsk.platform.payment3dsi.cardmanagement.CreditCardManagementServiceStub$StateProvinceCode'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [com.gsk.platform.payment3dsi.cardmanagement.CreditCardManagementServiceStub$StateProvinceCode]: no matching editors or conversion strategy found


I'm not sure why there are conversion errors? I should just be setting a key/value pair, no conversion needed. My bean looks like this:



<bean name="EnumUtil" class="com.gsk.platform.payment3dsi.util.EnumUtil" scope="tenant">
<property name="stateCodes">
<util:map map-class="java.util.HashMap" key-type="java.lang.String" value-type="com.gsk.platform.payment3dsi.cardmanagement.CreditCardManagementServiceStub.StateProvinceCode">
<entry key="US-IL" value="StateProvinceCode.Illinois" />
.
.
.
</util:map>
</property>
<property name="countryCodes">
<util:map map-class="java.util.HashMap" key-type="java.lang.String" value-type="com.gsk.platform.payment3dsi.cardmanagement.CreditCardManagementServiceStub.CountryCode">
<entry key="US" value="CountryCode.UnitedStates" />
<entry key="CA" value="CountryCode.Canada" />
</util:map>
</property>
</bean>


My Enum class looks like the following:



package com.gsk.platform.payment3dsi.util;

import java.util.HashMap;
import java.util.Map.Entry;

import com.gsk.platform.payment3dsi.cardmanagement.CreditCardManagementServiceStub.CountryCode;
import com.gsk.platform.payment3dsi.cardmanagement.CreditCardManagementServiceStub.StateProvinceCode;

public class EnumUtil {
private HashMap<String, StateProvinceCode> stateCodes;
private HashMap<String, CountryCode> countryCodes;

private HashMap<String, StateProvinceCode> getStateCodes() {
return stateCodes;
}

private HashMap<String, CountryCode> getCountryCodes() {
return countryCodes;
}

public void setStateCodes(HashMap<String, StateProvinceCode> stateCodes) {
this.stateCodes = stateCodes;
}

public void setCountryCodes(HashMap<String, CountryCode> countryCodes) {
this.countryCodes = countryCodes;
}

public String getRegionCodeForStateCode(StateProvinceCode stateProvinceCode){
for(Entry<String, StateProvinceCode> entry : stateCodes.entrySet()){
if(entry.getValue().equals(stateProvinceCode)){
return entry.getKey();
}
}
return null;
}

public StateProvinceCode getStateCodeFromRegionCode(String regionCode){
return getStateCodes().get(regionCode);
}

public String getCountryIsoForCountryCode(CountryCode countryCode){
for(Entry<String, CountryCode> entry : countryCodes.entrySet()){
if(entry.getValue().equals(countryCode)){
return entry.getKey();
}
}
return null;
}

public CountryCode getCountryCodeFromCountryIso(String countryCode){
return getCountryCodes().get(countryCode);
}
}


And I'm attempting to use this class in my code in the following manner:



@Resource(name = "EnumUtil")
private EnumUtil enumUtil;

.
.
.


billingAddress.setStateProvinceCode(enumUtil.getStateCodeFromRegionCode(billingAddressData.getRegion().getIsocode()));
billingAddress.setCountryCode(enumUtil.getCountryCodeFromCountryIso(billingAddressData.getCountry().getIsocode()));

Aucun commentaire:

Enregistrer un commentaire