Vladimir
Vladimir

Reputation: 13153

How to access map values in groovy by key containing dot?

I have map like this:

data = {user.name: "John",
        user.surname: "Doe",
        city: "NY"}

I can access attiribute 'city' this way:

data.city

Is there is a similar way to access 'user.name' attribute?

Upvotes: 6

Views: 5918

Answers (1)

tim_yates
tim_yates

Reputation: 171054

Assuming you meant:

data = [ 'user.name':"John", 'user.surname':"Doe", city:"NY" ]

(square braces for the map definition, and quotes round the dotted key names), I believe that

data.'user.name'

should do it

Upvotes: 16

Related Questions