1 package com.fasterxml.jackson.datatype.jsr310.deser.key;
2
3 import java.io.IOException;
4 import java.time.DateTimeException;
5 import java.time.Instant;
6 import java.time.format.DateTimeFormatter;
7
8 import com.fasterxml.jackson.databind.DeserializationContext;
9
10 public class InstantKeyDeserializer extends Jsr310KeyDeserializer {
11
12 public static final InstantKeyDeserializer INSTANCE = new InstantKeyDeserializer();
13
14 private InstantKeyDeserializer() {
15
16 }
17
18 @Override
19 protected Instant deserialize(String key, DeserializationContext ctxt) throws IOException {
20 try {
21 return DateTimeFormatter.ISO_INSTANT.parse(key, Instant::from);
22 } catch (DateTimeException e) {
23 return _handleDateTimeException(ctxt, Instant.class, e, key);
24 }
25 }
26 }
27