Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open to new serializer features? #52

Open
ejsmith opened this issue Mar 19, 2014 · 4 comments
Open

Open to new serializer features? #52

ejsmith opened this issue Mar 19, 2014 · 4 comments

Comments

@ejsmith
Copy link

ejsmith commented Mar 19, 2014

I would like to implement the ability to do the following things while serializing objects:

  1. Exclude fields that are using default values. I know some people will want to include these fields, but for my use case I would rather only serialize the minimum about of data necessary.
  2. Exclude empty collections. Same reasoning as above.
  3. Add ability to set maximum serialization depth. I would like to have the ability to set a maximum object depth for serialization in order to avoid serializing all of a really large object graph. This is because I am attempting to serialize unknown objects that I do not have control over.
  4. Add ability to set an exclusion list of fields that I do not want serialized.

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?

@prabirshrestha
Copy link
Member

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)?

@ejsmith
Copy link
Author

ejsmith commented Apr 4, 2014

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.

@prabirshrestha
Copy link
Member

@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 😃 )

this also means we need to add MaxDepthSerializationException which inherits SerializationException.

Feel free to post your thoughts on the interface.

@sicklittlemonkey
Copy link

I added pretty printing in about 25 lines. It would be nice if that was a serialization option too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants