This message was deleted.
# community-support
s
This message was deleted.
a
all types instantiated by Gradle implicitly implement ExtensionAware. So you can call
getExtensions().getExtensionSchema()
to get all extensions, along with their names. And then you can convert that list of names to JSON, if you want.
m
I don’t think this is quite what I’m looking for. For example, if my dsl is defined:
Copy code
myPluginDsl {
  key1 = "some-string"
  key2 {
    nestedKey = "another-string"
  }
}
How would I serialize this to json in my plugin? I’d like:
Copy code
{
  "key1": "some-string",
  "key2": {
    "nestedKey": "another-string"
  }
}
Currently I have to something like this in my plugin to get that structure:
Copy code
def data = [
    'key1': "${extension.key1.get()}",
    'key2':  [
        'nestedKey': "${extension.key2.nestedKey.get()}",
    ]
]
JsonOutput.toJson(data)
Is there a way to get extension dsl properties keys and values without manually setting the keys and values in the plugin?
a
ah okay, so the keys/properties aren’t dynamic, I misunderstood
you might have some luck searching for ‘groovy object to json’ - I don’t think Gradle has any relation to your question, other than it happens to use Groovy
m
How do I get the dsl object in the plugin? I don’t believe I can call extension.get() to get the key/value paris.
JsonOutput.toJson
should allow me to convert an groovy object to json. To build an object though, I need to know the keys beforehand, call
.get
on each one while rebuilding the dsl structure in my plugin.