CubeEngine / ReflecT

Typesafe serialization of data for Java
http://cubeisland.de
MIT License
13 stars 2 forks source link

System for not writing fields with default values to file #30

Open tlaundal opened 6 years ago

tlaundal commented 6 years ago

I've come in quite a few cases where I wish only the fields that differ from the default value in the class is saved.

For instance, if I have a section that has a type property, and some fields are only relevant to one type, or if I just have a lot of fields, and the default values will be fine for many of them in most cases.

It should still be possible to force some fields to be saved, but that could be done with an annotation. Or we could go the other way and annotate fields that only should be hidden if they have the default value.

Faithcaio commented 6 years ago

While it might not do everything you described, we already have a system to hide defaults: Reflected#setDefault I cannot remember if you can directly call addInheritedField & removeInheritedField directly too.

tlaundal commented 6 years ago

Can those defaults be used in custom converters? Or in MapNode?