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

Jackson 2.6: message converter should use type also for Iterable [SPR-13523] #18100

Closed
spring-projects-issues opened this issue Sep 30, 2015 · 4 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket)

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Sep 30, 2015

Michael Schoene opened SPR-13523 and commented

With #17903 you restrict the use of type to collections. Is this really necessary?

It would be nice to have the feature also for Iterable (as in Spring 4.2.0).


Affects: 4.2.1

Issue Links:

@spring-projects-issues
Copy link
Collaborator Author

Sébastien Deleuze commented

This question makes perfectly sense, but here I think we have to align with Jackson 2.6 behavior (see this commit), so we have to use exactly the same condition than them to enable this functionality, or that will not work as expected.

I think my proposal would be to ask on Jackson side first if they can support that for all iterables.
If they do, we could then enable this on our side, but currently I tend to think we can't extend the support to all iterables.

Any thoughts?

@spring-projects-issues
Copy link
Collaborator Author

Michael Schoene commented

Jackson 2.6.1 has support for Iterable. Using the following code

final Iterable<ComProfile> iter = getIterable();
final JavaType  javaType = objectMapper.getTypeFactory().constructType( new ParameterizedType()
{
    public Type getRawType() { return Iterable.class; }
    public Type getOwnerType() { return null; }
    public Type[] getActualTypeArguments() { return new Type[] { ComProfile.class }; }
});
System.out.println( objectMapper.writerFor( javaType ).writeValueAsString( iter ) );

I get type info in the json output. Jackson uses a IterableSerializer for this case. And this serializer does support type info (IterableSerializer:106):

if (typeSer == null) {
    currSerializer.serialize(elem, jgen, provider);
} else {
    currSerializer.serializeWithType(elem, jgen, provider, typeSer);
}

@spring-projects-issues
Copy link
Collaborator Author

Sébastien Deleuze commented

Thanks for your feedback.

I have tried to reproduce the issue but it seems that even if we don't pass the type information to ObjectMapper, for Iterable Jackson is able to find the type of each Iterable element (not the same behavior than List, Map, etc.). See TypeFactory#findTypeParameters()) and this test that passes with actual 4.2.2-BUILD-SNAPSHOT.

Did you guess this issue from reading the source code, or did you reproduce it in within a test case/project?
If you are able to reproduce it, could you provide a failing test case or a repro project that demonstrates the issue?

@spring-projects-issues
Copy link
Collaborator Author

Sébastien Deleuze commented

Hi Michael Schoene, could you please send me your feedback about how to reproduce the issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket)
Projects
None yet
Development

No branches or pull requests

2 participants