Open ejsmith opened 10 years ago
All the features are pretty interesting and seems like good to have in SimpleJson but I also don't want to increase the complexity of SimpleJson.
Out of curiosity I would want to know what you are using SimpeJson for (client/server or any other details)?
I am using it to serialize random unknown objects in our Exceptionless client. I need to be able to allow people to set exclusions and also to set serialization depth.
I started taking a look at implementing this, but, because the entire code base is static, there doesn't appear to be a way to keep track of the current serialization depth without making a decent amount of changes.
@ejsmith totally makes sense to add SerializationDepth in your case.
This was originally a fork from a different json parser library written in .NET 1.0 using hashtables and arraylist without generics, so definitely needs a lot of work on the api surface. Also one of the main reason why SimpleJson hasn't made it to v1 release is due to fact that I haven't been happy with the public api yet.
I do think IJsonSerializerStrategy
can solve the problem but the interface methods aren't good enough yet. It was a fast hack so that I could get fb c# sdk to internally use SimpleJson.
interface IJsonSerializerStrategy {
int SerializationDepth { get; }
bool TrySerializeNonPrimitiveObject(object input, out object output);
object DeserializeObject(object value, Type type);
}
I'm very much open to this interface being changed even though it would cause breaking change. (one reason why SimpleJson is still in alpha :smiley: )
this also means we need to add MaxDepthSerializationException
which inherits SerializationException
.
Feel free to post your thoughts on the interface.
I added pretty printing in about 25 lines. It would be nice if that was a serialization option too.
I would like to implement the ability to do the following things while serializing objects:
These seem like general purpose features, but I also understand that you don't want to have feature bloat. Would you guys be open to accepting a pull request like this?