groovy-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jesper Steen Møller <jes...@selskabet.org>
Subject Re: Java object conversion using ConfigSlurper
Date Wed, 16 May 2018 19:40:56 GMT

> On 16 May 2018, at 16.00, adithyank <adi.k.dev@gmail.com> wrote:
> 
> It works. But, If that `MyConfig` class has fields of `List` or `Map` types,
> then it does not work.

Actually it does work, too:

ConfigObject co = new ConfigSlurper().parse("""
myownconfig {
    name = 'Threadpool'
    displayLabel = "Thread Pool"
    threadCount = 12
    bleh {
        y = "not"
    }
    fleep = [ 'a', 'b' ]
    nested {
        threadCount = 12
    }
}
""")

public class MyConfig
{
     String name
     String displayLabel
     int threadCount
     Map bleh
     List fleep
     MyConfig nested
}

> I am looking this feature as a way of converting
> `ConfigObject` (inturn Map<String, Map&lt;Stirng, Map&lt;String,
> Map&lt;String>>>>....) of any levels to its respective java object with
> nested `List<anyclass>`, `Map<anyclass>`, `Other classes`.
> 

Anyway, I'm sure you can find examples which aren't covered now.

> 
> 1. I will look on the existing coercion codes to some how fit this use case
> of creating nested objects recursively
> or
> 2. `T ConfigObject.getAs(Class<T>)` can be implemented without affecting the
> existing semantics of `Map as SomeClass`
> 

I'd go for option "2" in that case - not that I can vote :-)

-Jesper




Mime
View raw message