It seems the it-block is being ignored because it is a normal class - but given the class has non-nullable fields, the it-block ctor is the only workable choice.
brianFri 19 Jul 2019
That is the way its designed to work:
const class is always deserialized using it-block
non-const class always deserialized using no arg make() + field sets
SlimerDudeTue 10 Dec 2019
Hmm... what this implies then, is that ALL fields on @Serializable non-const classes MUST be nullable and non-const; which seems quite the oppressive limitation.
If a class has an it-block ctor, in what situation would you not want to use it?
brianTue 10 Dec 2019
Not exactly. It means that non-const classes must have only mutable fields, but they can be non-nullable if you give them a default value.
Essentially the original design was for a mutable data class that let you do your sets via a text file. Then we added support for immutable classes using different mechanism via it-blocks. But its never going to work well to mix the two together. It was never intended to be an all encompassing format to do everything that Fantom allows in code. In fact, if I were do it again serialization would not even be included. I think the developer world has moved on from "pickling" objects to using standard language independent data formats like JSON, YAML, etc.
SlimerDude Wed 26 Jun 2019
When I try to de-serialise a non-const class with an it-block ctor, I get an error. Here's a side by side example with a const class:
It seems the it-block is being ignored because it is a normal class - but given the class has non-nullable fields, the it-block ctor is the only workable choice.
brian Fri 19 Jul 2019
That is the way its designed to work:
SlimerDude Tue 10 Dec 2019
Hmm... what this implies then, is that ALL fields on @Serializable non-const classes MUST be nullable and non-const; which seems quite the oppressive limitation.
If a class has an it-block ctor, in what situation would you not want to use it?
brian Tue 10 Dec 2019
Not exactly. It means that non-const classes must have only mutable fields, but they can be non-nullable if you give them a default value.
Essentially the original design was for a mutable data class that let you do your sets via a text file. Then we added support for immutable classes using different mechanism via it-blocks. But its never going to work well to mix the two together. It was never intended to be an all encompassing format to do everything that Fantom allows in code. In fact, if I were do it again serialization would not even be included. I think the developer world has moved on from "pickling" objects to using standard language independent data formats like JSON, YAML, etc.