2

What am I doing wrong here?

In my config file I have this line:

payments.mail.partner = [
      some_partner: "partner@email.com",
      other_partner: "partner2@email.com"
]

In a service I'm trying to access the email address depending on the key. It seems like I should be able to just access it like this, where the partner parameter corresponds to the key in the config array.

def getPartnerEmail(partner) {
 String partnerEmailAddress = grailsApplication.config.payments.mail.partner[partner]
}

However this just returns a Groovy object. I tried converting it to a string but no luck. Where am I going wrong?

Paul Erdos
  • 1,355
  • 2
  • 23
  • 47
  • Not that it should matter in this case, but you usually want to put what version of Grails you're using. – billjamesdev Feb 29 '16 at 21:35
  • it basically looks fine for me. Have you tried to debug your code in order to see what exactly you get? It is often very helpful to just do a `println partnerEmailAddress.dump()`... – rdmueller Feb 29 '16 at 21:41
  • This is what I get in the dump: – Paul Erdos Feb 29 '16 at 21:46
  • try to dump other parts of your code... start with `grailsApplication` and work yourself towards `grailsApplication.config.payments.mail.partner`. Since you force your result to be a `String`, you dump doen't give you a good clue... If you dump `grailsApplication.config.payments.mail.partner[partner]` directly, you'll see the content of the `ConfigObject` you get. – rdmueller Feb 29 '16 at 21:57
  • btw: could it be that the config from above is enclosed in another config closure or that there are other config parts which may overwrite your config? Anyway - you'll see this if you dump the right part of your expression :-) – rdmueller Feb 29 '16 at 21:58

0 Answers0