I'm sure this is a rather simple question but I'm at wits end as to how to solve it elegantly (a case statement doesn't sound like the most scalable option).
I have to convert and populate address data of one type and package it up for a webservice that is of a different type. Unfortunately, the types do not align and I will have to somehow map the two.
For instance, I have AddressData
which contains String AddressLine1
, String State
, etc... The other class, Address
, which needs to be populated is expecting a particular "StateProviceCode
" rather than a String for the state. How can I map the String
to a particular StateProviceCode
so I can just run the map and inject the correct state code?
If that doesn't make too much sense, I'm attempting to do something like the following:
Address billingAddress = new Address(); //to be populated
AddressData billingAddressData = updateStoredCardRequest.getPaymentInfo().getBillingAddress();
billingAddress.setAddressLine1(billingAddressData.getLine1()); //String->String
billingAddress.setCity(billingAddressData.getTown()); //String->String
billingAddress.setPostalCode(billingAddressData.getPostalCode()); //String->String
//based on the isocode of the billingAddressData.region, set the stateProviceCode of the billingAddress.
if(billingAddressData.getRegion().getIsocodeShort() == "US-IL"){
billingAddress.setStateProvinceCode(StateProvinceCode.Illinois);
}
Any help on ways to do this implementation would be great. Thank you so much.