As far as my understanding goes most of the serialization/de-serialization technique uses reflection to create object and set or get values. So why do one explicitly bind these attribute such as [XmlIgnore]... for xml, [Serializable]... in Binary serialisation, [JsonPropery]... Json.Net etc in the class. Since these are like cross cutting concerns as a far as an object concerned, cant we do the same outside the object?
If the concerns are separated the user can have control over which portion of the object graph/tree one needs to serialize/de- serialize under which context and how etc?
Is there any such framework that makes the entire serialization as aspect, i.e. outside the concern of the classes?
Edit1: My requirements are as follows My application stores the data in a huge tree structure. The customer requirement is to be able to serialize certain data in xml format, and certain portion of the data in Json (I do not know why such requirement) and we have most of the data serialized in binary as a legacy code.
Now that there are classes in which a portion of the data needs to be shown in XML format and another portion (these can be part of the xml data or binary serialization data as well) in Json.
So I am looking for a solution in which
- Classes should not be aware of any serialization specific attributes, instead the serializer framework can give enough tools to easily do serialization without touching the class.
- The framework should allow persisting both private and public data which I wanted. This can be specific to a class or instance or specific to some properties of an instance in some context.
E.g.- SaveTemplate: Should save only few nodes from each branch of the tree
- SaveDocument: Should save one branch from the tree completely
- SavePackage: Should save entire tree.
- Should allow serialize into different format, such as xml, binary, json etc for different purposes.
So I am planning to evaluate certain Serialization framework to achieve the same. I found Json.Net which can give me the following
- No serialization tag to be put for public properties just like xml serialization.
- Backward compatibility to Binary Serialization. i.e. I do not have to change the binary serialization interface implementation
- Does not need a parameter less constructor.
However I still need the capability mentioned in point 2) and 3) above. I have not yet explored Json.Net in detail or any other framework.
Does any framework can help me achieve the same?