groovy-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "K Adithyan (tech)" <adi.k....@gmail.com>
Subject Java object conversion using ConfigSlurper
Date Thu, 10 May 2018 19:33:25 GMT
Team,

ConfigSlurper can be used to parse groovy-styled configurations and get
them as *ConfigObject. *As an additional feature, either ConfigSlurper can
be enhanced or a new class can be written to return java object itself from
the configuration. Example below

*config.groovy*

myownconfig {
      name = 'Threadpool'
     displayLabel = "Thread Pool"
     threadCount = 12
}
----------------------------------------------

*MyConfig.java*

public class MyConfig
{
     String name;
     String displayLabel
     int threadCount
}
-----------------------------------------------
Usage:

MyConfig myConfig = new ConfigClassConver().object('myownconfig',
MyConfig.class)
println myConfig.name
println ...
-----------------------------------------------


I have implemented this functionality for one of my project needs. If the
team feels, it can be added groovy itself, then the discussion can proceed
in what could be the class name, what features, etc.

What I have given is a sample only. There are couple of other features,
like ConfigSlurper.merge(), parsing multiple files in one directory
(optionally, recursive too), etc.

I feel this will be a good addition to groovy itself.

Pls comment

Regards,

K Adithyan
India

Mime
View raw message