Skip to content

Instantly share code, notes, and snippets.

@emersonf
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emersonf/a5bec01225f540b1a167 to your computer and use it in GitHub Desktop.
Save emersonf/a5bec01225f540b1a167 to your computer and use it in GitHub Desktop.
Jackson Joda DateTime serialisation from Spring Boot breaks with DelegatingWebMvcConfiguration
@Configuration
@EnableAutoConfiguration
@ComponentScan("internal.sandbox")
public class Application {
public static void main(String[] args) {
new SpringApplicationBuilder(Application.class).run(args);
}
}
public class Foo {
private DateTime dateTime;
public DateTime getDateTime() {
return dateTime;
}
public void setDateTime(DateTime dateTime) {
this.dateTime = dateTime;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-parent</artifactId>
<version>1.1.3.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>internal</groupId>
<artifactId>sandbox-spring-boot</artifactId>
<version>1.0.0</version>
<dependencies>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-joda</artifactId>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</project>
@RestController
public class SampleController {
@RequestMapping(value = "/foo")
public Foo getFoo() {
Foo foo = new Foo();
foo.setDateTime(DateTime.now());
return foo;
}
}
@Configuration
public class WebMvcConfiguration extends DelegatingWebMvcConfiguration {
@Override
@Bean
public RequestMappingHandlerMapping requestMappingHandlerMapping() {
RequestMappingHandlerMapping mapping = super.requestMappingHandlerMapping();
mapping.setRemoveSemicolonContent(false);
return mapping;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment