jacob-carlborg/orange

Completely Ignore fields

InfiniteRegression opened this issue · 3 comments

mixin NonSerialized!(b);

does not remove problems on serializing a modified structure. That is, the serialize still looks for the value and if it can't find it, it throws.

It would be nice if there was an ignore attribute that completely ignored the field and did not throw if it does not exist.

That's how it's intended to work. There's also a test for that [1]. Could you please provide an example where it doesn't work?

[1] https://github.com/jacob-carlborg/orange/blob/master/tests/NonSerialized.d

I am trying to serialize a structure that contains both persistent settings across runs of the app and also settings that do not need to be serializes. Some of these are added and taken away as the program develops. When add a new element that isn't meant to persist in the same structure that is being serializes, the NonSerialized template mixin does not prevent it from being serializes. It IS serializes but does not store the value. You say it is intended to work this way, but this cases a problem when one adds a new field using that attribute because the variable is not in the old stored data. Hence, we need an attribute that can prevent the field from being serializes at all(goes further than NonSerialized so it never even attempts to look at it. It just jumps over it in the loop for getting the fields. It won't show up in the filed nor be checked by the code for any reason so no errors can occur.

It should be maybe 10 lines of code extra. Create a new IgnoreSerialized template and attribute and just ignore them when found in the code.

The code is already ignoring fields that are marked as non serialized [1][2], which is verified by this test [3]. If it does not behave as you describe above, could you please provide a minimal code example that demonstrates this behavior?

[1] https://github.com/jacob-carlborg/orange/blob/master/orange/serialization/Serializer.d#L1493-L1498

[2] https://github.com/jacob-carlborg/orange/blob/master/orange/serialization/Serializer.d#L1551-L1556

[3] https://github.com/jacob-carlborg/orange/blob/master/tests/NonSerialized.d