Skip to content

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

Closed

Description

@spring-projects-issues

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:

Activity

  1. spring-projects-issues commented on Sep 30, 2015

    @spring-projects-issues
    CollaboratorAuthor

    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?

  2. spring-projects-issues commented on Oct 1, 2015

    @spring-projects-issues
    CollaboratorAuthor

    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);
    }
  3. spring-projects-issues commented on Oct 1, 2015

    @spring-projects-issues
    CollaboratorAuthor

    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?

  4. spring-projects-issues commented on Oct 26, 2015

    @spring-projects-issues
    CollaboratorAuthor

    Sébastien Deleuze commented

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

  5. added
    type: enhancement
    in: web
    on Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: web

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions