I’ve got a fixedPoint math library objects that have the actual values in a few fields and then like a billion properties that seem to hold converted versions of those values to pass along or something?
I.E.
//important info
public fp x = 0;
public fp y = 0;
//not important info
public fp4 xxxx { get; }
public fp4 xxxy { get; }
public fp4 xxyx { get; }
etc times a billion...
Obviously the only thing I want serialized are the important variables. I spent hours trying to figure out why json was trying to compare variables I didn’t make only to find out that it was because of these properties while it was checking for circular references and throwing me tons of errors. And now I’m ripping my hair out over what seems like should be basic functionality XD. Any help would be greatly appreciated. Bonus points if I don’t have to edit the library files themselves since that might break if I update from that repo.
To reiterate, I only want to serialize fields. No properties.
2
Answers
If you can modify property declaration
You can use
[JsonIgnore]
attribute over unwanted props.Define a list of ignored props
Use this helper https://github.com/jitbit/JsonIgnoreProps.
You can specify list of members to ignore.
Use it like
or use custom contract resolver, filtering out everything but fields
Then use it like:
I assume that problem can be in data type which you’re trying to save.
In your case fp should be primitive type and serializable. Same restrictions to object which store this info.
If FixedPoint data can’t be serializalbe then you should convert it to some type which can.
For ex.: