groovy-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adithyank <adi.k....@gmail.com>
Subject Re: Java object conversion using ConfigSlurper
Date Tue, 15 May 2018 07:15:31 GMT
Ok. Thanks Daniel.

I will proceed in the below way.

Pls advice

1. I will write new class `ConfigCustomObjectBuilder` in
   `ConfigSlurper.groovy` to convert given ConfigObject to custom class
instance

2. I will add below new method in ConfigObject

   T getAs(Class<T> dataStructure)
   {
       return ConfigCustomObjectBuilder.build(ConfigObject, Class<T>
dataStructure)
   }

3. So, the callers of the method can do the below steps

   a. ConfigObject co = new ConfigSlurper().parse(...)
   b. Do required co.merge(...)
   c. MyConfig mc = co.getAs(MyConfig)
   d. use mc further

4. Optionally, we can implement `asType(Class)` method in `ConfigObject`
class
   so that callers can use below syntax

   c. MyConfig mc = co as MyConfig

Regards,

K Adithyan
India
--




Daniel.Sun wrote
> I think it is useful especially for Java developers. PR is welcome.
> 
> P.S. it would be better if the Java class is a Java bean(with getters and
> setters)





--
Sent from: http://groovy.329449.n5.nabble.com/Groovy-Dev-f372993.html

Mime
View raw message