-
Notifications
You must be signed in to change notification settings - Fork 40.8k
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
spring.jackson.date-format configuration does not affect serialisation of Joda DateTime instances #2225
Comments
FYI, I'm using 1.2.0.RELEASE |
@csavory Can you provide some more information about what you're trying to configure and how you're trying to configure it please? Any |
All I'm trying to do is get the Joda DateTime objects written out as Strings instead of timestamps. It works if I put the This is how I'm trying to configure: jackson:
date-format: com.fasterxml.jackson.databind.util.ISO8601DateFormat
serialization:
write-dates-as-timestamps: false |
@wilkinsona do I remove the waiting-for-feedback label now that I responded? |
That helps, thanks. In investigating #2322 I'd been using |
@wilkinsona here is my configuration I'm using. <dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-joda</artifactId>
</dependency> @Bean
public Module jodaModule() {
return new JodaModule();
} |
You're hitting a limitation in Jackson. Jackson treats the date format configured on the |
@wilkinsona I'm not sure I agree that writing it out as a string is a limitation of Joda. If you look at if you look at The problem is that I want to do this globally through the ObjectMapper, but something is preventing Spring Boot from configuring the ObjectMapper as The problem is that I want to do this globally through the ObjectMapper, but something is preventing Spring Boot from configuring the ObjectMapper as |
The configuration of This configuration: spring:
jackson:
date-format: "YYYY-MM-dd"
serialization:
write_dates_as_timestamps: true Gives me this output: {"date":1421343027885,"dateTime":1421343027895} Note that both the On the other hand this configuration: spring:
jackson:
date-format: "YYYY-MM-dd"
serialization:
write_dates_as_timestamps: false Gives me this output: {"date":"2015-01-15","dateTime":"2015-01-15T17:31:28.884Z"} Note that both are now being formatted as strings but that only I see this behaviour both with and without Spring HATEOAS on the classpath. If you're seeing behaviour that's different to what I've described above, then please describe your application's configuration and its dependencies in more detail. Ideally, please provide a sample that shows a |
Andy, thanks for the info. It'll take me a couple of days to put together a sample for you. Is there a place I check it into or is just my repo fine? Sent from my iPhone
|
Thanks. Either something in your own repo, or as a PR against Spring Boot issues is fine. |
Thanks. You've annotated your configuration class with With these three changes your sample app produces this output:
|
I've reopened this as I'd like to address the Jackson limitation that stops |
Thank you @wilkinsona When we started using Spring Boot (v0.5), HypermediaAutoConfiguration was not part of Boot so that was how it was configured for us. By the way, there is no documentation in the Boot docs about how to configure HATEOAS support with Boot. The only docs are found at https://github.com/spring-projects/spring-hateoas/blob/master/readme.md |
You don't really need to do anything to configure HATEOAS support other than having the right things on the classpath, i.e. there's not much to say in the manual that wouldn't end up being a duplication of Spring HATEOAS's existing documentation. I've just added a starter to help with the classpath part. We also have a sample application that shows Spring HATEOAS in action with Spring Boot. |
I agree with you that you need to do anything to configure HATEOAS support for Boot. But the configuration is different if I am using: I would think since there is a difference in how you configure it the latter scenario (even if it's a negative configuration) it would be worth mentioning in the Boot reference. If it was there in the reference, I would have never created this issue b/c I would have read it there and removed my As I said before, just trying to help folks out coming after me and don't look through the specifics of how all the AutoConfigurators work by looking at the code. As I said before, just trying to help folks out coming after me and don't look through the specifics of how all the AutoConfigurators work by looking at the code. |
@wilkinsona this solution stops working when I merged in my temporary solution for #2360 where my I don't see any |
@wilkinsona nevermind. I found a way to put our WebConfig back to @Configuration
public class WebConfig extends WebMvcConfigurerAdapter implements EnvironmentAware { It's working again. |
I have the same problem as @csavory described - if I add a WebConfig that extends
I'm using boot spring boot 1.4.0. Does my WebConfig need to implement P.S. I'm using WebConfig to add resource handlers for swagger. |
@pavelfomin this issue is closed. If you believe you've found an issue with a recent version of Spring Boot, please create separate issue. Consider using stackoverflow or gitter for questions. |
I have breakpoints set in both:
MappingJackson2HttpMessageConverterConfiguration.mappingJackson2HttpMessageConverter
JacksonObjectMapperConfiguration.jacksonObjectMapper
I can see that there is an ObjectMapper bean being created because jacksonObjectMapper is never called and thus
MappingJackson2HttpMessageConverterConfiguration
uses this otherObjectMapper
and not the one that I'm trying to configure. How do I tell what is creating that bean? From that logs, my guess is that it isHypermediaSupportBeanDefinitionRegistrar.registerBeanDefinitions
that is doing it from:If I put a breakpoint there it is definitely called before
MappingJackson2HttpMessageConverterConfiguration.mappingJackson2HttpMessageConverter
but it is so hard to tell if this is the root of my problem. I can't remove that dependency because it is so pervasively used in my project that it would take me hours to refactor.The text was updated successfully, but these errors were encountered: