jsr310

Serialize Date, Instant to ISO 8601 when using JSR310 java.time in spring

点点圈 提交于 2019-12-07 13:15:45
问题 I am replacing JodaTime by JSR310 and the module of JodaTime() was working fine. I am trying to reconfigure the serialization of my dates in my spring-boot application. I can't keep both so I am looking for a way to serialize/deserialize my date to ISO 8601. I followed the advices here but this doesn't help : http://lewandowski.io/2016/02/formatting-java-time-with-spring-boot-using-json/ This is my JacksonConfig.java with the objectMapper : @Configuration public class JacksonConfig extends

Serialize Date, Instant to ISO 8601 when using JSR310 java.time in spring

时间秒杀一切 提交于 2019-12-05 19:09:50
I am replacing JodaTime by JSR310 and the module of JodaTime() was working fine. I am trying to reconfigure the serialization of my dates in my spring-boot application. I can't keep both so I am looking for a way to serialize/deserialize my date to ISO 8601. I followed the advices here but this doesn't help : http://lewandowski.io/2016/02/formatting-java-time-with-spring-boot-using-json/ This is my JacksonConfig.java with the objectMapper : @Configuration public class JacksonConfig extends RepositoryRestMvcConfiguration { private static final Logger logger = LoggerFactory.getLogger

Jackson deserialization issue for ZonedDateTime

佐手、 提交于 2019-12-05 05:26:59
I've the following field in a class I use during deserialization of a service that I'm consuming. private ZonedDateTime transactionDateTime; The service I'm consuming may return a Date or DateTime using the pattern: yyyy-MM-dd'T'HH:mm:ss.SSSZ Let me give 2 examples of what the service returns: 2015-11-18T18:05:38.000+0200 2015-11-18T00:00:00.000+0200 While first one works well, the latter causes the following exception to be thrown during deserialization: java.time.format.DateTimeParseException: Text '2015-11-18T00:00:00.000+0200' could not be parsed at index 23 I'm using; Spring Boot 1.3.1

Java 8新特性探究(七)深入解析日期和时间-JSR310

淺唱寂寞╮ 提交于 2019-12-05 02:22:08
博客一个月没更新了,这次给大家讲下java8时间与日期API。 众所周知,日期是商业逻辑计算一个关键的部分,任何企业应用程序都需要处理时间问题。应用程序需要知道当前的时间点和下一个时间点,有时它们还必须计算这两个时间点之间的路径 。但java之前的日期做法太令人恶心了,我们先来吐槽一下 吐槽java.util.Date跟Calendar Tiago Fernandez做过一次投票,选举最烂的JAVA API,排第一的EJB2.X,第二的就是日期API。 槽点一 最开始的时候,Date既要承载日期信息,又要做日期之间的转换,还要做不同日期格式的显示,职责较繁杂(不懂单一职责,你妈妈知道吗?纯属恶搞~哈哈) 后来从JDK 1.1 开始,这三项职责分开了: 使用Calendar类实现日期和时间字段之间转换; 使用DateFormat类来格式化和分析日期字符串; 而Date只用来承载日期和时间信息。 原有Date中的相应方法已废弃。不过,无论是Date,还是Calendar,都用着太不方便了,这是API没有设计好的地方。 槽点二 坑爹的year和month Date date = new Date(2012,1,1); System.out.println(date); 输出Thu Feb 01 00:00:00 CST 3912 观察输出结果,year是2012+1900,而month

Comparing ThreeTen backport to JSR-310

我怕爱的太早我们不能终老 提交于 2019-12-04 20:46:29
问题 For some reasons, we can't use java 8 right now - we're still stuck at java 7. However, I'd like to use the new JSR-310 date/time APIs right now, using the official backport ThreeTen. Its homepage states: The backport is NOT an implementation of JSR-310, as that would require jumping through lots of unnecessary hoops. Instead, this is a simple backport intended to allow users to quickly use the JSR-310 API on Java SE 6 and 7. Questions: What are your experience with ThreeTen? Are there some

Registering JacksonJsonProvider with ObjectMapper + JavaTimeModule to Jersey 2 Client

∥☆過路亽.° 提交于 2019-12-03 12:34:58
I'm trying to marshal response containing ISO formatted timestamp like that: { ... "time" : "2014-07-02T04:00:00.000000Z" ... } into ZonedDateTime field in my domain model object. Eventually it works if I use solution that is commented in following snippet.There are many similar questions on SO but I would like to get a specific answer what is wrong with another approach which uses JacksonJsonProvider with ObjectMapper + JavaTimeModule ? ObjectMapper mapper = new ObjectMapper(); mapper.registerModule(new JavaTimeModule()); JacksonJsonProvider provider = new JacksonJsonProvider(mapper); Client

How do I format a javax.time.Instant as a string in the local time zone?

时光总嘲笑我的痴心妄想 提交于 2019-12-02 23:46:56
How do I format a javax.time.Instant as a string in the local time zone? The following translates a local Instant to UTC , not to the local time zone as I was expecting. Removing the call to toLocalDateTime() does the same. How can I get the local time instead? public String getDateTimeString( final Instant instant ) { checkNotNull( instant ); DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder(); DateTimeFormatter formatter = builder.appendPattern( "yyyyMMddHHmmss" ).toFormatter(); return formatter.print( ZonedDateTime.ofInstant( instant, TimeZone.UTC ).toLocalDateTime() ); } Note

Is it a bug in jackson-datatype-jsr310 deserializer?

假装没事ソ 提交于 2019-12-02 17:26:10
问题 I know that's presumptuous to image found a bug in a library used every day by thousands of developpers. So I think the answer to my title question is "NO !!!", but ... I have an object containing a date that I receive from my front end (JS), and I store it into a MongoDB database. I use Spring to get this object (with a REST Controller), and Spring to perform persistance (with a MongoDBRepository). My computer is configured with a CEST clock, so GMT+2 (UTC +0200). The date in my POJO is

Jooq LocalDateTime fields use system timezone instead of session timezone

笑着哭i 提交于 2019-12-02 04:28:30
I'm using jooq (v3.11.9) to access a MySQL database that is running in UTC time. I've using generated entities and am using JSR-310 time types. The option I'm using in my config: <javaTimeTypes>true</javaTimeTypes> My understanding is that the MySQL datetime and timestamp types both map to LocalDateTime which makes sense as MySQL doesn't store timezone information with the times. However when I run queries on a machine in a different timezone (in my case EST) the dates are all in my local machine timezone even though the session timezone is UTC . I've confirmed that the session timezone is UTC

jOOQ - support for JSR310

◇◆丶佛笑我妖孽 提交于 2019-12-01 03:07:00
Does jOOQ provide support for JSR310 in combination with PostgreSQL? In particular, I am trying to use the following classes: java.time.Instant java.time.LocalDate java.time.LocalTime java.time.LocalDateTime I am storing in the following data types (as per http://www.postgresql.org/docs/9.1/static/datatype-datetime.html ): java.time.Instant : timestamp with timezone java.time.LocalDate : date java.time.LocalTime : time without timezone java.time.LocalDateTime : timestamp without timezone Are these data types correct? Does jOOQ support translation between java.sql.Timestamp , java.sql.Date and