-
Notifications
You must be signed in to change notification settings - Fork 41.2k
Allow the formatting of java.time.LocalDate etc to be configured via the environment #4217
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
Comments
Seem like the bean @Bean
@ConditionalOnMissingBean(Jackson2ObjectMapperBuilder.class)
public Jackson2ObjectMapperBuilder jacksonObjectMapperBuilder() { Am I right ? |
That code isn't from Rather than copy and pasting snippets of code into an issue, can you please provide a project that we can |
Here is the link where you can find my project : https://github.com/sixrandanes/seriajack There is a failure test which describes the problem : Thank you in advance for your reply |
If you want to configure the formatting of @Autowired
private Jackson2ObjectMapperBuilder builder;
@PostConstruct
public void postConstruct() {
this.builder.serializers(new LocalDateSerializer(new DateTimeFormatterBuilder()
.appendPattern("dd/MM/yyyy").toFormatter()));
} |
Thank you very much. It helps me ! |
+1 For being able to configure the new Date/Time formats via the environment. |
Hello, I just realized that there is a new property :
Is that property have something to do with that issue ? |
No, that's the joda date format, not the Java8 date format. |
ok sorry, I red too fast :-) |
@wilkinsona I tried the |
@cbornet I don't believe so. If you're having trouble please post on Stack Overflow using the |
I had to add @Bean
public ObjectMapper myJacksonObjectMapper() {
return this.builder.createXmlMapper(false).build();
} to make it work. If not present, the autoconfigured objectMapper is created before the Also, I see that in SB 1.4, there will be a |
For reference, |
Work for me now. |
+1 to this.
I set:
but In REST reply I still see the time in my local timezone. |
@drenda you should use a |
@cbornet Should this solve my timezone problem?
In my case doesn't work. The timezone seems to be my local timezone instead of UTC. Thanks |
@drenda for which date type ? |
@cbornet I'm using LocalDateTime (jdk8). I figured .timezone() works only with |
Duplicates #5523 |
Hello,
1/ Description
I try to serialize a
LocalDate
(java 8) from my JPA entity into a specific pattern (dd/MM/yyyy).Everything works fine if I put the annotation
@JsonFormat(pattern="dd/MM/yyyy")
on each date of my JPA entity.That solution is too heavy because I don't want to put this annotation on each date of all my jpa entites, So, I was looking for a better solution by applying some global configuration with spring boot.
I found the properties
spring.jackson.date-format
andspring.jackson.locale
but I can't get them to work. I don't know if it's really a bug or I miss something in my project / configuration.I am using Java8, spring-boot (1.2.6.RELEASE) with spring data jpa 1.9, and I have this in my classpath : 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.6.3'
To be precise that I am only working with
spring-data-jpa
and notspring-data-rest
.2/ Unit testing
I made a unit test and I have that output :
(I use
spring.jackson.date-format
property)Without the property in my yaml file, I've got this :
With the property but without specifying any format (blank), I've got this :
With the property and If i specify any format (
dd/MM/yyyy
ordd-mm-yyyy
, or even a class) , I've got the same:I've got the same result with the property :
spring.jackson.locale
3/ build.gradle
4/ application.yml
5/ application.java
6/ JPA entity
7/ Controller
The text was updated successfully, but these errors were encountered: