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

JsonDoc ignores transient modifier (leading to StackOverflowError) #228

Open
joffrey-bion opened this issue Apr 6, 2017 · 0 comments
Open

Comments

@joffrey-bion
Copy link

In my project, I have a few classes that together make a dependency cycle. This cycle does not cause any trouble during serialization because I marked some fields as transient to break the cycle.

JsonDoc, however, ignores the transient modifier when creating object templates in JSONDocTemplateBuilder, and goes into infinite recursion up to the traditional StackOverflowError.

I could fix the issue by adding the following code in getDeclaredAllFields():

    private static Set<JSONDocFieldWrapper> getAllDeclaredFields(Class<?> clazz) {
        // ...

        for (Field field : declaredFields) {
            if (!shouldBeInTemplate(field)) {
                continue;
            }
           // ...
        }
        // ...
    }

    private static boolean shouldBeInTemplate(Field field) {
        return !field.isSynthetic() && !Modifier.isTransient(field.getModifiers());
    }

Similarly, in AbstractSpringJSONDocScanner.appendSubCandidates(), all fields are recursively explored and added to the candidates even if they are marked transient and thus will not be output by the API. It can easily be fixed by a similar check in the loop on the fields.

I can make a PR if you want to save time.

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

1 participant