First, let me state that I’m working with the equivalent of Java 6, so newer techniques may not solve my issue.
I have a callout with a response object that contains a field called currentMode (it relates to payments). currentMode can have the following values: monthly, quarterly, semiannually or annually.
I have a different callout that has a response with the following object and nested objects. I’m just going to include the values from a specific response:
"requested": {
"eftOrCreditCardPremiumAmount": {
"amt": 277.80
},
"monthlyPremiumAmount": {
"amt": 285.80
},
"quarterlyPremiumAmount": {
"amt": 833.40
},
"semiAnnuallyPremiumAmount": {
"amt": 1666.80
},
"annuallyPremiumAmount": {
"amt": 3333.60
}
},
I need to display in my app the correct dollar amount based on the customer’s mode of payment. So if currentMode is monthly, I need to display the amt from monthlyPremiumAmount.
I’m thinking I can take the currentMode and somehow search the nested object names and see which object name begins with the string value for currentMode. But I’m drawing a blank on how to do it. All I can think of is having a bunch of if else statements – something like: if monthly get monthlyPremiumAmount, else if quarterly get quarterlyPremiumAmount, else if semiannually… You get the idea.
I’m sure there’s a more concise way to do what I need to do, isn’t there?