Skip to content
Advertisement

Tag: jsr310

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 to do it? Answer A given LocalDateTime object can not be modified, since those are immutable. But you

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: Jackson2ObjectMapperBuilder config: Now if i’m receiveing: the result is birthDate=1970-01-02 I’m able to do so by setting leniency to false: And then it’s working by throwing MismatchedInputException But it’s a little brutal

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 available in the clock to e.g. create a ZonedDateTime like this? ZonedDateTime.ofInstant(clock().instant(), clock().getZone()) Wouldn’t it then make sense to have a method zonedDateTime() in

How to abstract away java.time.Clock for testing purposes in Spring

I have a question with regards to the question Time dependent unit tests Let’s say I build Spring application which contains service interface and its implementation If I want to change clock in test, I would have to “pollute” production code and interface with e.g. setClock method as follows: In test, I can invoke, e.g.: How can I abstract away

ThreeTen-Backport error on Android – ZoneRulesException: No time-zone data files registered

I’m using ThreeTen-Backport library for my Android project (because java.time is not yet implemented in android development). When I write LocalDate today=LocalDate.now(); or LocalTime time=LocalTime.now(); I get the following exception: The same line of code works well in another java project I have, which uses the native java.time library. I searched for a possible solution but couldn’t find anything useful:

Jackson deserialization issue for ZonedDateTime

I’ve the following field in a class I use during deserialization of a service that I’m consuming. 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:

Advertisement