I use JsonFX to serialize an instance to json, and I need to ignore some attributes and preprocess others. How do I do that ? The doc is not very clear on that.
My class looks a bit like this one :
public class Primitive{
public string type;
public float[] vertices;
public int[] indices;
public int[] edgeIndices;
public Scene scene;
When outputting json, I need to ignore the scene
attribute (that's the whole 3d scene) and to pre-process the vertices
, indices
, edgeIndices
using some compression scheme.
And, obviously, I need the symmetrical operation when receiving json.
But how ?
You can use
[JsonIgnore]
along withJsonResolverStrategy
:Or, you can use data contract attributes along with
DataContractResolverStrategy
:(Note however that
DataContractResolverStrategy
is broken in .Net 3.5., so you can't use it if you're stuck on that old version.)Update
One way to "transform" properties during serialization is to use proxy properties, for instance:
Then write and read like so: