1 package com.fasterxml.jackson.datatype.jsr310.deser.key;
2
3 import java.io.IOException;
4 import java.time.DateTimeException;
5 import java.time.Year;
6
7 import com.fasterxml.jackson.databind.DeserializationContext;
8
9 public class YearKeyDeserializer extends Jsr310KeyDeserializer {
10
11 public static final YearKeyDeserializer INSTANCE = new YearKeyDeserializer();
12
13 protected YearKeyDeserializer() {
14
15 }
16
17 @Override
18 protected Year deserialize(String key, DeserializationContext ctxt) throws IOException {
19
20 try {
21 return Year.of(Integer.parseInt(key));
22 } catch (NumberFormatException nfe) {
23 return _handleDateTimeException(ctxt, Year.class, new DateTimeException("Number format exception", nfe), key);
24 } catch (DateTimeException dte) {
25 return _handleDateTimeException(ctxt, Year.class, dte, key);
26 }
27 }
28 }
29