Re: Records support in JSON

2023-09-06 Thread Guillaume Laforge
Neat! It looks great! Thank you. On Wed, Sep 6, 2023 at 4:04 PM Paul King wrote: > I have a prototype fix. It alters RecordTypeASTTransformation to emit > a BeanInfo class in the emulate case and MetaClassImpl to handle > properties within native records. The following script then works: > > ===

Re: Records support in JSON

2023-09-06 Thread Paul King
I have a prototype fix. It alters RecordTypeASTTransformation to emit a BeanInfo class in the emulate case and MetaClassImpl to handle properties within native records. The following script then works: @RecordOptions(mode=EMULATE) record PersonA(String name) {} @RecordOptions(mode=NA

Re: Records support in JSON

2023-09-05 Thread Guillaume Laforge
I also forget the fact that Groovy records are not always Java records when running on older JDKs... So it needs to make the difference with real and groovy-specific fallthrough records. On Tue, Sep 5, 2023 at 10:46 AM Guillaume Laforge wrote: > Sure, I just created: > https://issues.apache.org/

Re: Records support in JSON

2023-09-05 Thread Guillaume Laforge
Sure, I just created: https://issues.apache.org/jira/browse/GROOVY-11167 Also, thanks for the workaround. I ended up just using a POGO instead, but I hadn't thought of implementing a Map. I guess JsonOutput needs to be updated here

Re: Records support in JSON

2023-09-04 Thread Paul King
We aren't picking up the metabean properties for the record correctly. Would you like to file a bug report? Workarounds are to call "toMap()" (or *.toMap() on the list), or do something like: ``` @AutoImplement record Person(String name) implements Map { Set entrySet() { toMap().entrySet() } } `

Records support in JSON

2023-09-04 Thread Guillaume Laforge
Hi, I was a bit surprised by this behavior with serializing records in JSON. I was expecting this assertion to pass: import groovy.json.JsonOutput record Person(String name) {} assert JsonOutput.toJson([new Person('Guillaume')]) == '[{"name":"Guillaume"}]' Instead, I got [{}] Shouldn't records