groovydsl

How to create a DSL Groovy config file using an arbitrary Map (dynamic object)

怎甘沉沦 提交于 2019-12-14 03:27:34
问题 How do I convert an arbitrary Groovy map / list to the config style DSL syntax that Groovy provides? Example: def config = [ 'test': 'lalala', 'nestedObject': [ foo1: 'foo1 val', foo2: 'foo2 val', nested2: [ anInt: 5, anArray: ['a', 'b', 'c'], anIntArray: [1, 2, 3] ] ] ] To something like: test = 'lalala' nestedObject { foo1 = 'foo1 val' foo2 = 'foo2 val' nested2 { anInt = 5 anArray = ['a', 'b', 'c'] anIntArray = [1, 2, 3] } } UPDATE: Re-appropriating this post to explicitly ask for a dynamic