Skip to content

Poor diagnostics when Jackson cannot deserialise an application/json payload due to a missing deserialiser [SPR-15582] #20141

Closed
@spring-projects-issues

Description

@spring-projects-issues

Andy Wilkinson opened SPR-15582 and commented

Consider this application that uses Guava's ImmutableList:

package com.example;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.google.common.collect.ImmutableList;

@SpringBootApplication
@RestController
public class Unhelpful415Application {

	public static void main(String[] args) {
		SpringApplication.run(Unhelpful415Application.class, args);
	}

	@RequestMapping(path="create", method=RequestMethod.POST,  consumes=MediaType.APPLICATION_JSON_UTF8_VALUE)
	public String create(@RequestBody MyPojo pojo) {
		return "Created";
	}

	public static class MyPojo {

		private ImmutableList<String> things;

		public ImmutableList<String> getThings() {
			return things;
		}

		public void setThings(ImmutableList<String> things) {
			this.things = things;
		}

	}

}

A POST to /create results in a 415 response (application/json is not supported). This is arguably wrong as JSON is supported and there's nothing that the client can do to fix the problem. It's actually the server that is at fault due to using ImmutableList and not configuring Jackson's Guava module. In my opinion, a 5xx response would be more appropriate.

The problem is exacerbated by the fact that Spring Framework 4.3 provides no further diagnostics for the failure. Arguably this is a regression as, with 4.2, a helpful warning message was logged:

2017-05-24 09:53:10.135  WARN 74298 --- [nio-8080-exec-5] .c.j.MappingJackson2HttpMessageConverter : Failed to evaluate Jackson deserialization for type [simple type, class com.example.Unhelpful415Application$MyPojo]: com.fasterxml.jackson.databind.JsonMappingException: Can not find a deserializer for non-concrete Collection type [collection type; class com.google.common.collect.ImmutableList, contains [simple type, class java.lang.String]]

This was removed by the changes for #18735. Enabling debug logging for org.springframework.http.converter.json doesn't provide any more information (and I don't think it should be necessary anyway).


Affects: 4.3.8

Reference URL: #18735

Issue Links:

Referenced from: commits be93ee7, 7eaedf2

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: regressionA bug that is also a regression

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions