Tag: jsr310

ZonedDateTime的jackson反序列化问题

我在我正在使用的服务的反序列化过程中使用的类中有以下字段。 private ZonedDateTime transactionDateTime; 我正在使用的服务可以使用以下模式返回Date或DateTime: yyyy-MM-dd’T’HH:mm:ss.SSSZ 让我举两个服务返回的例子: 2015-11-18T18:05:38.000 + 0200 2015-11-18T00:00:00.000 + 0200 虽然第一个工作正常,但后者导致在反序列化期间抛出以下exception: java.time.format.DateTimeParseException:无法在索引23处解析文本’2015-11-18T00:00:00.000 + 0200′ 我正在使用; Spring Boot 1.3.1 Jackson 2.6.4(包含JSR310模块) 这需要自定义反序列化类吗?

将ThreeTen backport与JSR-310进行比较

出于某些原因,我们现在不能使用java 8 – 我们仍然坚持使用java 7。 但是,我现在想使用新的JSR-310 date/time APIs 310日期 JSR-310 date/time APIs ,使用官方的backport ThreeTen 。 其主页说明: 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 […]

如何将javax.time.Instant格式化为本地时区中的字符串?

如何将javax.time.Instant为本地时区中的字符串? 以下内容将本地Instant转换为UTC ,而不是按照我的预期转换为本地时区。 删除对toLocalDateTime()的调用toLocalDateTime()如此。 我怎样才能获得当地时间? 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() ); } 注意:我们使用的是JSR-310参考实现的旧版本0.6.3 。

使用Spring Data REST时如何更改Jacksons Configuration?

我正在尝试配置Jackson以ISO 8601格式显示JSR 310瞬间。 @Configuration class Jackson { @Bean static ObjectMapper objectMapper() { ObjectMapper objectMapper = new ObjectMapper().findAndRegisterModules(); objectMapper.disable( SerializationFeature.WRITE_DATES_AS_TIMESTAMPS ); return objectMapper; } } 然而,这不是一个独特的Bean,实际上我只想禁用这一个设置。 所以我真的不想创建ObjectMapper,就像在其上指定一个设置一样。 java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘org.springframework.boot.actuate.autoconfigure.EndpointWebMvcHypermediaManagementContextConfiguration$MvcEndpointAdvice’: Injection of autowired dependencies failed; nested exception is […]

使用Jackson JSR310模块反序列化LocalDateTime

我正在使用描述Jackson数据类型JSR310页面的库,但我仍然难以让它工作。 我配置了以下bean: @Bean @Primary public ObjectMapper objectMapper() { ObjectMapper mapper = new ObjectMapper(); mapper.registerModule(new JSR310Module()); return mapper; } 当我调用我的REST API时,日期格式输出是yyyy-MM-dd’T’HH:ss.SSSSSS ,例如2015-04-11T00:10:38.905847 。 这可以通过我的AngularJS代码处理得很好。 当我想向REST API提交内容时,日期将发布为yyyy-MM-dd’T’HH:mm:ss.SSS’Z’ ,例如2015-04-09T08:30:00.000Z jackson一直在抱怨’Z’。 如果我查看文档中的LocalDateTimeDeserializer ,它使用DateTimeFormatter.ISO_LOCAL_DATE_TIME ,该文件沸腾到ISO_LOCAL_DATE’T’ISO_LOCAL_TIME并且它提到它没有覆盖区域。 所以我想我应该在我正在创建的ObjectMapper上设置DateFormat : @Bean @Primary public ObjectMapper objectMapper() { ObjectMapper mapper = new ObjectMapper(); mapper.registerModule(new JSR310Module()); mapper.setDateFormat(new SimpleDateFormat(“yyyy-MM-dd’T’HH:mm:ss.SSS’Z'”)); return mapper; } 但这没有任何作用。 我将其更改为yyyy-MM-dd类的简单内容,但序列化日期保留为以前的格式,反序列化也不受影响。 我在这做错了什么才能让它发挥作用? 我的JavaScript代码中的日期格式是,据我所知ISO 8601格式…

jOOQ – 支持JSR310

jOOQ是否支持JSR310与PostgreSQL结合使用? 特别是,我试图使用以下类: java.time.Instant java.time.LocalDate java.time.LocalTime java.time.LocalDateTime 我存储在以下数据类型中(根据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 这些数据类型是否正确? jOOQ是否支持java.sql.Timestamp , java.sql.Date和java.sql.Time以及上面的四个类(两个方向)之间的转换?

我应该使用threeten而不是joda-time

我遇到了https://blog.joda.org/2009/11/why-jsr-310-isn-joda-time_4941.html 。 1)我目前正在将Java Calendar迁移到joda-time。 我想知道,我应该使用threeten而不是joda-time吗? 三生产准备好了吗? 2)三个库和joda-time库可以在同一个应用程序中一起存在吗? 因为我正在使用一些使用joda-time库的第三方库。 3)joda-time会不会成为一个放弃项目,因为有三个?

如何使用jsr310 DateTimeFormatter解析不区分大小写的字符串?

jsr-310有一个方便的类DateTimeFormatters ,它允许你构造一个DateTimeFormatter 。 我特别喜欢pattern(String)方法 – 请参阅javadoc 但是,我遇到了一个问题,即这是区分大小写的 – 例如 DateTimeFormatters.pattern(“dd-MMM-yyyy”); 与“01-Jan-2012”匹配,但不与“01-JAN-2012”或“01-jan-2012”匹配。 一种方法是断开字符串并解析组件,或者另一种方法是使用Regex用区分大小写的字符串替换不区分大小写的字符串。 但感觉应该有一个更简单的方法……