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

StackOverflowError with contentConverter that returns array/list type (same as #357) #1704

Closed
ghost opened this issue Jul 14, 2017 · 4 comments
Milestone

Comments

@ghost
Copy link

ghost commented Jul 14, 2017

Java Version: 1.8
Affected Jackson versions: at least from 2.8.0 to 2.8.9, also 2.8.10-SNAPSHOT
Unaffected Jackson versions: 2.9.0.pr1 - 2.9.0.pr4

This is exactly the same problem as #357, contentConverter creates a StackOverflowException, using the exact same code.

public class Test {
    //Example 1: List
    static class Example1 {
        @JsonSerialize(contentConverter = Converter1.class)
        public List<String> list = Collections.emptyList();
    }

    static class Converter1 extends StdConverter<String, List<Integer>> {
        @Override public List<Integer> convert(String value) {
            return Collections.emptyList();
        }
    }

    //Example 2: Array
    static class Example2 {
        @JsonSerialize(contentConverter = Converter2.class)
        public List<String> list = Collections.emptyList();
    }

    static class Converter2 extends StdConverter<String, String[]> {
        @Override public String[] convert(String value) {
            return new String[0];
        }
    }

    //Example 3: Exactly the code from #357
    static class A {}

    static class B {
        @JsonSerialize(contentConverter = AToStringConverter.class)
        public List<A> list = Arrays.asList(new A());
    }

    static class AToStringConverter extends StdConverter<A, List<String>> {
        @Override public List<String> convert(A value) {
            return Arrays.asList("Hello world.");
        }
    }

    public static void main(String[] args) throws JsonProcessingException {
        System.out.println(PackageVersion.VERSION);
        //All three examples throw the exception
        new ObjectMapper().writeValueAsString(new Example1());
        new ObjectMapper().writeValueAsString(new Example2());
        new ObjectMapper().writeValueAsString(new B());
    }
}
@cowtowncoder
Copy link
Member

This is #357, which is only fixed for 2.9. It will not be fixed for earlier versions, due to concerns that fix might break other parts of code.

@cowtowncoder cowtowncoder added this to the 2.9.0 milestone Jul 14, 2017
@cowtowncoder cowtowncoder reopened this Jul 15, 2017
@cowtowncoder
Copy link
Member

Actually forgot to ask: is this literally same thing that #357 had (and that was fixed); or possible follow-up (that was alluded to)? As per my first comment, part that was fixed will not be backported.
But if there is something different for 2.9.0 I would want to follow up.

@ghost
Copy link
Author

ghost commented Jul 15, 2017

It's the exact same thing.
Looking at the date of your comments on the old issue I was assuming the fix was in 2.8.X - my bad.

@ghost ghost closed this as completed Jul 15, 2017
@cowtowncoder
Copy link
Member

@Quurks ah. Makes sense, np.

This issue was closed.
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