Questions tagged [jsr310]
JSR 310: Date and Time API in Java JDK 8. Please use the [java-time] tag for questions relating to date & time in Java SE 8.
111
questions
1
vote
1
answer
149
views
Ending 0's are getting truncated from millisecond part of ZonedDateTime object in Java11
I am upgrading my spring boot application to spring boot 2.7.8 and Java 11. I getting different rest response of ZonedDateTime object after upgrade.
My request contain "2023-06-23T18:13:06.630Z[...
0
votes
1
answer
39
views
JSR310 when to use which classes?
I would like to verify if my understanding of JSR310 classes use-cases are correct, below a diagram with classes, and how i see them fit:
Database (UTC)
||
\/
OffsetDateTime (...
2
votes
0
answers
460
views
Querydsl`s JPASQLQuery uses java.sql.Date instead of java.time.LocalDate
I have a simple PostgreSQL table:
CREATE TABLE public.test_entity (
id int8 NOT NULL,
title varchar NOT NULL,
created_at date NOT NULL,
CONSTRAINT test_entity_pkey PRIMARY KEY (id)
);
...
0
votes
1
answer
431
views
How to serialize Java8 LocalDateTime to json as calendar object using Jackson
Im using jackson-datatype-jsr310 module, which supports LocalDateTime serialization.
but by default, it serializes date/time as "[2022,6,29,17,15,54]".
But I need to override this behaviour ...
-2
votes
1
answer
803
views
jackson json date format convert
Please help to change date format.
**Source** json file
**Target** Employee Object
I need support for converting file json date to Object. from file
{
"dateOfBirth": {
"year"...
11
votes
1
answer
11k
views
Spring Boot: Java 8 date/time type `java.time.OffsetDateTime` not supported by default
I have added the JavaTimeModule but still not able to get OffsetDateTime working on getting some data from RethinkDB
@Configuration
public class JacksonOffsetDateTimeMapper{
@Bean
@Primary
public ...
0
votes
1
answer
919
views
@Cacheable annotation cannot work as expected when deserialize beans with LocalDateTime type property
I found that the annotation @Cacheable cannot work when the method returns a Java Bean type, this is the complete description:
I annotated @Cacheable on a method to use spring cache:
@Cacheable(...
1
vote
1
answer
5k
views
Jackson ObjectMapper.findAndRegisterModules() not working to serialise LocalDateTime
I am using Java Spring-boot RestController. I have a sample GET API in which I am sending LocalDateTime.now() in response body. I have customised the Jackson ObjectMapper to register jackson-datatype-...
0
votes
3
answers
851
views
Modifiying time in LocalTimeDate object
Given a LocalDateTime object in Java. How do I set the time for this to 00:00:00 ?
One way is to create a new LocalDateTime object with the same date as this one and set it to 0.
Is there another way ...
0
votes
2
answers
963
views
SQL Server type to generate Instant in Mybatis Generator
I want to define columns in SQL Server in order for Mybatis Generator to generate java.time.Instant or java.time.OffsetDateTime. According to Mybatis Generator Core, columns with type ...
2
votes
1
answer
3k
views
InvalidDefinitionException with jackson-datatype-jsr310 version 2.12.3
I'm having an issue with the jackson jsr310 datatype using version > 2.12.0, while this works perfectly with version 2.11.4.
This is my POJO:
import java.time.OffsetDateTime;
public class Pojo {
...
7
votes
3
answers
3k
views
LocalDate: equals vs isEqual
LocalDate in Java has two similar methods equals and isEqual.
What's the difference between them? When do they output different results?
2
votes
1
answer
267
views
How to restrict jackson from parsing millis to LocalDate in json request
I need to validate LocalDate fields in json requests. What i want is to prevent deserializing numbers as miilis to LocalDate. Here is example:
I have an entity:
public class Test {
@NotNull
@...
2
votes
1
answer
1k
views
How to configure jackson-modules-java8 in Ktor
I am trying to configure jackson-modules-java8 with Ktor and Jackson but to no avail.
The module is added to gradle.build
dependencies {
...
implementation 'com.fasterxml.jackson.datatype:...
0
votes
3
answers
503
views
How to implement Java 8 LocalTimeDeserializer?
I have been looking for implementing a custom deserializer using LocalTimeDeserializer class of Jackson API.
However, I am getting below error while actually deserializing properties using this class.
...
2
votes
1
answer
519
views
Algorithm used by java.time.Period.between() when dealing with different-length months?
When using java.time.Period.between() across months of varying lengths, why does the code below report different results depending on the direction of the operation?
import java.time.LocalDate;
import ...
3
votes
3
answers
576
views
Find next occurrence of a time, like TemporalAdjuster
Is there anything in JSR-310 for finding the next occurrence of a given time? I'm really looking for the same thing as this question but for times instead of days.
For example, starting with a date of ...
1
vote
0
answers
244
views
Jackson LocalDate deserialization error only in release-APK
I have an Android App, which receives data via an JSON Api.
I then convert the data with Jackson ObjectMapper.
I also included com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.11.0 in my build....
5
votes
2
answers
159
views
JSR310 Year.parse() throws DateTimeParseException with values < 1000
I'm trying to parse Year String values in the range from 0 to 1000 with java.time.Year.parse(), however parsing fails with java.time.format.DateTimeParseException: Text '999' could not be parsed at ...
2
votes
1
answer
792
views
Persisting java.time.LocalTime into oracle with Types.TIME loses fractional seconds precision
I have a behavior with Oracle which I'm not sure is intended or not.
I am playing with the various types of the java date/time API, using them at the JDBC level.
I am trying to persist an instance ...
3
votes
2
answers
224
views
JSR310 How to internationalize a pattern for a month-day?
Im trying to format a date without a year (just day and month, e.g 12.10)
DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT) still yield year for me (12.10.20).
so I tried DateTimeFormatter....
1
vote
1
answer
737
views
DateTimeFormatterBuilder with default zone id? [duplicate]
I have a requirement where if ISO date time does not specify zone offset, I should assume Europe/Bratislava's current offset.
Basically "2020-03-26T22:47:32.497" -> "2020-03-26T22:47:32.497+01:00"
...
0
votes
3
answers
658
views
How to parse JSR-310 date to Instant?
I'm trying to parse lets say "2020-01-12+01:00" with JSR-310 time.
I read it via DateTimeFormatter.ofPattern("yyyy-MM-ddVV"), however now if I want to transform that into a Instant via Instant.from(...
6
votes
0
answers
261
views
ZonedDateTime ISO-8601 parsing: why is colon in timezone ID required? [duplicate]
I have the following tests.
@Test
void withoutColon_fails() {
ZonedDateTime.parse("2019-01-24T12:10:58.036820+0400");
}
@Test
void withColon_ok() {
ZonedDateTime.parse("2019-01-24T12:10:58....
0
votes
1
answer
325
views
How to use Jackson DataType: JSR310 Deser standalone?
I'm in a scenario where I'm converting from type A to type B. Type A has a date field which is of type YearMonth, and type B's date field is a String. I don't want to reinvent the wheel, so it'd be ...
3
votes
1
answer
2k
views
Jooq LocalDateTime fields use system timezone instead of session timezone
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>...
2
votes
2
answers
786
views
Zone adjustment not taken into account when parsing RFC 3339 date time
(Migrated from CodeReview)
I am experimenting and trying to understand Java Time better. My code is not working as expected and I want to ask the reason, probably because there is a misunderstandment ...
0
votes
1
answer
49
views
java.time not properly deserialised using jackson
Based on what's described here, I should be serialising ZonedDateTime object using the JSR-310 representation rather than the numeric one. However, I'm getting the numeric representation. What could ...
3
votes
1
answer
4k
views
Serialize LocalDateTime with only milliseconds with Jackson
I want to serialize a LocalDateTime to textual format while only showing milliseconds. I tried the following example:
final ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new ...
1
vote
1
answer
2k
views
How to deserialize dates with offset ("2019-01-29+01:00") to `java.time` related classes?
I've refactored some legacy code within Spring Boot (2.1.2) system and migrated from java.util.Date to java.time based classes (jsr310). The system expects the dates in a ISO8601 formated string, ...
14
votes
2
answers
2k
views
Why does the java.time.Clock has zone information?
Why does java.time.Clock has zone information? From the Clock you only can get an Instant when calling the instant() method - which is a time without zone info.
Is the only purpose to have the zone ...
0
votes
3
answers
2k
views
Jackson Data Binding for LocalDate[] using annotation
I am converting a JSON file into Java object using Jackson with Java 8 Module. But while converting JSON array to LocalDate[] application is throwing an exception.
How to convert below JSON array to ...
8
votes
1
answer
7k
views
Java 8 Exception: com.fasterxml.jackson.datatype.jsr310.deser.InstantDeserializer has no default (no arg) constructor
I have a model class that has a field:
@JsonDeserialize(using = InstantDeserializer.class)
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSZ")
private OffsetDateTime offsetDt;
When a ...
2
votes
1
answer
122
views
Good design of a localized YearWeek according to JSR-310 [closed]
I need an object that represents a localized concept of a seven days week. That object is pretty much the same as the YearWeek found in the ThreeTen-Extra library, except that the first day and the ...
2
votes
1
answer
1k
views
DatepickerDialog with LocalDate instead of Day Month Year
I'm trying to make a custom DatePickerDialog class that will fire the onDateSet Listener Callback, but instead of containing the "Day" "Month" and "year" values, I want to overload the constructor to ...
2
votes
1
answer
747
views
Conflict between Swagger2 and jackson-datatype-jsr310 in Spring Boot application
I am creating a REST API using Spring Boot and have issues serialising LocalDateTime when I use Swagger 2.
Without Swagger the JSON output is like this:
{
"id": 1,
...
"...
2
votes
0
answers
85
views
Elasticsearch 6.3: why DateHistogramAggregationBuilder doesn't support JSR-310?
In ES 6.3 DateHistogramAggregationBuilder seems to only support joda DateTimeZone and not JSR-310 ZoneId. Am I missing something ? (I used to use DateHistogramBuilder which support java ZoneId but ...
6
votes
1
answer
138
views
How to ignore java.time package in Android Studio
I am currently working on an Android Studio project with a minimum API version of 17 (JellyBean), so I cannot use the java.time package. Instead, I am using the ThreeTen backport for Android (com....
1
vote
0
answers
293
views
best practice to set the formatter of LocalTime to ISO
After searching and looking in spring source code, I found I can configure application-wide default LocalTime formatter (mainly for use in Request Parameters) in one of two ways (both by subclasses ...
3
votes
3
answers
4k
views
JJWT / Jackson alter the ObjectMapper used
For a project I am working on, I am required to use Spring Security and JSON Webtokens as provided by the library io.jsonwebtoken (jjwt). One of the claims I am required to add to my generated token ...
20
votes
1
answer
12k
views
Are java.util.Date and java.util.Calendar deprecated?
It seems that the new java.time API offers everything from java.util.Date and much more.
Is there any reason to use java.util.Date when the newer java.time API is there since Java 8?
Should java.util....
1
vote
2
answers
2k
views
Java ZonedDateTime and British Summer Time
I am currently looking at ZonedDateTime behaviour when the date is inside and outside British Summer Time.
The British Summer Time starts on 25th of March and it adds one hour (+1).
I have created ...
2
votes
1
answer
146
views
Java new time API compiles and break at run time
I am trying to use consistently the Java 8 date time API, I am looking for explications behind this behaviour :
Instant.from(LocalDateTime.of(2017,01,01,0,0,0,0))
Compiles just fine but yields to :
...
8
votes
2
answers
10k
views
java.time.LocalDate not supported in native queries by latest Spring Data/Hibernate?
Problem: Native queries with Spring Data returning dates return java.sql.Date not java.time.LocalDate, despite the setup.
Context: A new project with Spring Boot 2.0.0.M5 (the latest), Hibernate 5.2....
2
votes
1
answer
1k
views
Spring Boot Jackson JSR-310 - ZonedDateTime always timestamp
Consider this Spring MVC controller started using Spring Boot:
@RequestMapping("/foo")
public Foo get() {
return new Foo();
}
public class Foo {
@Getter
@Setter
private ZonedDateTime ...
8
votes
2
answers
7k
views
Jackson (de)serialization of Java8 date/time by a JAX-RS client
I'm making a serivce client for a REST endpoint, using a JAX-RS client for the HTTP requests and Jackson to (de)serialize JSON entities. In order to handle JSR-310 (Java8) date/time objects I added ...
29
votes
1
answer
2k
views
Joda Time and Java8 Time difference
I'm looking for a solution to calculate the months between two date. I think joda or java8 time can do it. But when I compare them I found something really weird.
import java.text.ParseException;
...
2
votes
1
answer
1k
views
converting ZonedDateTime to Calendar using ThreeTen-Backport (JSR 310)
I am trying to convert a ZonedDateTime object to a Calendar object using the back-port of the java.time classes (JSR 310): the ThreeTen-Backport project.
My understanding was that the back-port was ...
4
votes
0
answers
182
views
Multiple datasources with Jsr310JpaConverters not work
When there is a LocalDateTime attribute in Entity, serialization fails when using the repository interface query, and when a single data source is working.
When I only use the following configuration ...
5
votes
1
answer
10k
views
How to save Java 8 Instant to MongoDB as Date type using Spring MongoTemplate?
I have a Java class having an Instant type of member variable:
public class SomeRecord {
private String someId;
private Instant someInstant;
// getters and setters
}
I am using ...