raj
raj

Reputation: 11

how to copy elements from one map to another in freemarker

For example If I have values like below in json { "ABC": { "x": false, "y": false, "z": true } }

I want to make new map and copy values from ABC, how to achieve?

Upvotes: 1

Views: 132

Answers (1)

ddekany
ddekany

Reputation: 31152

FreeMarker assumes that maps won't change, and it provides no way to modify them. So there's no copying either, but of course you can assign a map to a variable. (Some may point out that you can actually add together maps with +, but that just creates a view, and doesn't modify an existing map.)

If you really need to modify/copy maps, then you will need to expose some Java methods for that. At least, you will need one that creates a new Map of the desired type (like LinkedHashMap). After that though, you can use the Java API-s via ?api, like myMap?api.putAll(otherMap).

Upvotes: 1

Related Questions