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?
If you wanted to do it that way, iterate over map. keySet() and the rest will work as you expected. It should work if you use s. key & s.
Add Item to a Map The first way is using the square brackets for the key. This way useful if you have a dynamic key name for example the key name join with index. The second way is using a key separate with map name by a dot ".". Or this example also working in Groovy.
Maps are generally used for storing key-value pairs in programming languages. You have two options to declare a map in groovy. First option is, define an empty map and put key-value pairs after. Second option is declaring map with default values.
2. The each Method. In Groovy, maps created with the literal notation are ordered.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With