-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Legger til CustomZonedDateTimeDeSerializer for håndtering av ZDT. (#458)
* Legger til CustomZonedDateTimeDeSerializer for håndtering ZDT. CustomZonedDateTimeDeSerializer støtter deserialisering av zdt uten og med ms fra 0-6 siffer. ZDT uten sekund del skal fortsatt feile. * Legger til CustomZonedDateTimeDeSerializer for håndtering ZDT. CustomZonedDateTimeDeSerializer støtter deserialisering av zdt uten og med ms fra 0-6 siffer. ZDT uten sekund del skal fortsatt feile. * Erstatter NANO_OF_SECOND med MILLI_OF_SECOND. * Støtter offset (+01:00) * Støtter region id.
- Loading branch information
Showing
5 changed files
with
114 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
soknad/src/main/java/no/nav/k9/søknad/CustomZonedDateTimeDeSerializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package no.nav.k9.søknad; | ||
|
||
import com.fasterxml.jackson.core.JsonParser; | ||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.DeserializationContext; | ||
import com.fasterxml.jackson.databind.JsonDeserializer; | ||
|
||
import java.io.IOException; | ||
import java.time.ZonedDateTime; | ||
import java.time.format.DateTimeFormatter; | ||
import java.time.format.DateTimeFormatterBuilder; | ||
import java.time.temporal.ChronoField; | ||
|
||
public class CustomZonedDateTimeDeSerializer extends JsonDeserializer<ZonedDateTime> { | ||
|
||
static final DateTimeFormatter zonedDateTimeFormatter = new DateTimeFormatterBuilder() | ||
// 2024-08-14T10:05:56 | ||
.appendPattern("yyyy-MM-dd'T'HH:mm:ss") | ||
.optionalStart() | ||
// 2024-08-14T10:05:56.111 | ||
.appendFraction(ChronoField.MILLI_OF_SECOND, 0, 9, true) | ||
.optionalEnd() | ||
// 2024-08-14T10:05:56.111+02:00 | ||
.appendPattern("ZZZZZ") | ||
.optionalStart() | ||
// 2024-08-14T10:05:56.111+02:00[Europe/Oslo] | ||
.appendLiteral('[') | ||
.appendZoneRegionId() | ||
.appendLiteral(']') | ||
.optionalEnd() | ||
.toFormatter(); | ||
|
||
@Override | ||
public ZonedDateTime deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException { | ||
String value = p.getValueAsString(); | ||
return ZonedDateTime.parse(value, zonedDateTimeFormatter); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters