Java object conversion using ConfigSlurper

classic Classic list List threaded Threaded
13 messages Options
12
MG
Reply | Threaded
Open this post in threaded view
|

Re: Java object conversion using ConfigSlurper

MG
Non-PMC +1 on using getAs, because I feel the semantics are sufficiently different, and trying to retrofit this might lead to unexpected edge cases now and/or headaches in the future. What do others think ?

-------- Ursprüngliche Nachricht --------
Von: adithyank <[hidden email]>
Datum: 16.05.18 16:00 (GMT+01:00)
Betreff: Re: Java object conversion using ConfigSlurper

Yes Jesper,

It works. But, If that `MyConfig` class has fields of `List` or `Map` types,
then it does not work. 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`.

Now, what decision can we take? Below are the options

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`

Pls advice



--
Sent from: http://groovy.329449.n5.nabble.com/Groovy-Dev-f372993.html
MG
Reply | Threaded
Open this post in threaded view
|

Re: Java object conversion using ConfigSlurper

MG
In reply to this post by adithyank
Non-PMC +1 on using getAs, because I feel the semantics are sufficiently different, and trying to retrofit this might lead to unexpected edge cases now and/or headaches in the future. What do others think ?

-------- Ursprüngliche Nachricht --------
Von: adithyank <[hidden email]>
Datum: 16.05.18 16:00 (GMT+01:00)
Betreff: Re: Java object conversion using ConfigSlurper

Yes Jesper,

It works. But, If that `MyConfig` class has fields of `List` or `Map` types,
then it does not work. 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`.

Now, what decision can we take? Below are the options

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`

Pls advice



--
Sent from: http://groovy.329449.n5.nabble.com/Groovy-Dev-f372993.html
Reply | Threaded
Open this post in threaded view
|

Re: Java object conversion using ConfigSlurper

Jesper Steen Møller
In reply to this post by adithyank

> On 16 May 2018, at 16.00, adithyank <[hidden email]> 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



12