1 package com.fasterxml.jackson.datatype.jsr310.deser.key;
2
3 import static java.time.temporal.ChronoField.DAY_OF_MONTH;
4 import static java.time.temporal.ChronoField.MONTH_OF_YEAR;
5
6 import java.io.IOException;
7 import java.time.DateTimeException;
8 import java.time.MonthDay;
9 import java.time.format.DateTimeFormatter;
10 import java.time.format.DateTimeFormatterBuilder;
11
12 import com.fasterxml.jackson.databind.DeserializationContext;
13
14 public class MonthDayKeyDeserializer extends Jsr310KeyDeserializer {
15
16 public static final MonthDayKeyDeserializer INSTANCE = new MonthDayKeyDeserializer();
17
18
19 private static final DateTimeFormatter PARSER = new DateTimeFormatterBuilder()
20 .appendLiteral("--")
21 .appendValue(MONTH_OF_YEAR, 2)
22 .appendLiteral('-')
23 .appendValue(DAY_OF_MONTH, 2)
24 .toFormatter();
25
26 private MonthDayKeyDeserializer() {
27
28 }
29
30 @Override
31 protected MonthDay deserialize(String key, DeserializationContext ctxt) throws IOException {
32 try {
33 return MonthDay.parse(key, PARSER);
34 } catch (DateTimeException e) {
35 return _handleDateTimeException(ctxt, MonthDay.class, e, key);
36 }
37 }
38 }
39