I'm using Spring-Boot 1.2.2 with this code:
@RequestMapping(value = "/dates", method = RequestMethod.GET)
public Date getDates() {
return new Date();
}
which returns this response:
1433241315047
How can I make it return "Sun May 31 16:26:43 IDT 2015"
?
I found some examples on Google like mapper.configure(SerializationConfig.Feature.WRITE_DATES_AS_TIMESTAMPS, false)
but can't figure out where should I write this...
UPDATE:
I added 2 dependencies to pom.xml:
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.7</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-joda</artifactId>
<version>2.4.0</version>
</dependency>
and added spring.jackson.date-format=yyyy-MM-dd
to application.properties
and still getting timestamps, so I started to eliminate all unnecessary code and found that removing the @Configuration
annotation from my WebConfiguration.java
solve the this issue:
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import java.util.List;
@Configuration
@EnableWebMvc
@ComponentScan
public class WebConfiguration extends WebMvcConfigurerAdapter {
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> httpMessageConverters) {
httpMessageConverters.add(new MappingJackson2HttpMessageConverter());
}
}
I guess this class somehow override date-format setting... So can I specify the date-format here?