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

Expose Jackson2CodecSupport mime types for custom override [SPR-15474] #20034

Closed
spring-projects-issues opened this issue Apr 22, 2017 · 3 comments
Closed
Assignees
Labels
in: web type: enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

@spring-projects-issues spring-projects-issues commented Apr 22, 2017

Daniel Lavoie opened SPR-15474 and commented

Some web services offers JSON content without properly typing the content type. For example, a bad api serving json content but setting the content-type to text/plain. The brand new shiny WebClient relies on the Jackson2CodecSupport to decode the stream. Saldy, there is now way to manually define the supported mime types.

The class Jackson2CodecSupport does not offers any means to override the supported mime types.

I can provide a PR to expose an extension mechanism.

Jackson2JsonDecoder

@Override
public boolean canDecode(ResolvableType elementType, MimeType mimeType) {
  JavaType javaType = this.objectMapper.getTypeFactory().constructType(elementType.getType());
  // Skip String: CharSequenceDecoder + "*/*" comes after
  return (!CharSequence.class.isAssignableFrom(elementType.resolve(Object.class)) &&
    this.objectMapper.canDeserialize(javaType) && supportsMimeType(mimeType));
}

Jackson2CodecSupport

  protected static final List<MimeType> JSON_MIME_TYPES = Arrays.asList(
    new MimeType("application", "json", StandardCharsets.UTF_8),
    new MimeType("application", "*+json", StandardCharsets.UTF_8));


  protected boolean supportsMimeType(MimeType mimeType) {
    return (mimeType == null ||
      JSON_MIME_TYPES.stream().anyMatch(m -> m.isCompatibleWith(mimeType)));
  }

Affects: 5.0 M1

Referenced from: commits 8231812

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Apr 24, 2017

Rossen Stoyanchev commented

Sure, send a PR.

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Apr 24, 2017

Daniel Lavoie commented

Any guideline you wish that I stick to ? Should this extension mecasnism be appliable to other codecs than jackson's ?

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Apr 24, 2017

Rossen Stoyanchev commented

Let's focus on Jackson to start. For constructor based injection each encoder/decoder has to provide them anyway.

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

No branches or pull requests

2 participants