4

I'm trying to retain a few business configs on the domain through yaml file.

Structure of yml config file:

bank:
    accountType1:
        debit:
            - Product1
            - Product2
        hybrid:
            - ProductX
            - ProductY
    accountType2:
        debit:
            - Product1
            - Product2
            - Product3
        hybrid:
            - ProductX
            - ProductY
            - ProductZ

I have the below enums for on the domain.

enum AccountType{ ACCOUNT_TYPE1, ACCOUNT_TYPE2}
enum Feature{ DEBIT, HYBRID}
enum Products { Product1, Product2, Product3, ProductX, ProductY, ProductZ }

I would like to seek help to get these business configs as a MultikeyMap, or a nested map, but using enums as keys. For eg:

Map<AccountType, Map<Feature, List<Products>>

Basically I would like the config to perform the following lookup:

if AccountType = accountType1 & Feature = debit, then return [Product1,Product2]

I couldn't find a way to do this elegantly via config files, as it always initialises to null

@ConfigurationProperties(prefix="bank")
public class ProductResolver {
Map<AccountType, Map<Feature, List<Products>> configMap 
  // NestedMap, Apache MultiKeymap or something similar either should be ok for me
}

Any experts, please could you guide me?

2
  • this helps? Commented Mar 2, 2022 at 21:13
  • @Eugene I am aware of Map<String,String> but couldn’t make it work with enums and multikey maps; which is what am looking for. Any clue if this is doable? Commented Mar 3, 2022 at 6:50

1 Answer 1

3

If you can slightly change you mappings, like this:

bank:
 map:
  accountType1:
    debit:
     - Product1
     - Product2
    hybrid:
     - ProductX
     - ProductY

Then below config actually worked for me just fine:

@ConfigurationProperties(prefix = "bank")
public class NewProps {

    private Map<AccountType, Map<String, List<Product>>> map = new HashMap<>();

    public Map<AccountType, Map<String, List<Product>>> getMap() {
        return map;
    }

    public void setMap(Map<AccountType, Map<String, List<Product>>> map) {
        this.map = map;
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.