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

json filter fails to serialize any content with a relationship #31

Open
snide opened this issue Feb 10, 2015 · 0 comments
Open

json filter fails to serialize any content with a relationship #31

snide opened this issue Feb 10, 2015 · 0 comments
Assignees
Labels

Comments

@snide
Copy link
Contributor

snide commented Feb 10, 2015

Originally reported by asprouse in webhook/webhook#47

According to the documentation using Webhook it should be possible generate quick static JSON endpoints. This pattern works like a charm until a relationship is added and then the filter will cause the following error:

TypeError: Converting circular structure to JSON

This problem could be avoided by creating a de-cycle filter or option on the existing json filter. There is an existing public domain de-cycle algorithm written by Crockford which could be used. This algorithm replaces already seen objects with a refrence object containing a JSONPath which can be used by the consumer to reestablish the circular references after deserialization.

The issue with the decycle filter is that it will leave in other potentially unwanted objects in the reverse relation. A the solution to this would be to not serialize reverse relations. Figuring this out in the template layer might be a bit tricky without attaching metadata to the object to indicate the reverse relationship. A potentially simpler solution would be to assume that any property with a circular reference is indeed a reverse relation. Limiting the depth of recursion while serializing might be another option.

Maybe I am missing something, since this functionality is a listed in the "common pattern" section of the documentation, but if I am not this should be supported without having to resort to manually serializing in swig.

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

No branches or pull requests

2 participants