-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bb45b00
commit f834d6f
Showing
5 changed files
with
53 additions
and
92 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
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
...c/main/java/com/fasterxml/jackson/datatype/jsr310/deser/key/YearMonthKeyDeserializer.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 com.fasterxml.jackson.datatype.jsr310.deser.key; | ||
|
||
import static java.time.temporal.ChronoField.MONTH_OF_YEAR; | ||
import static java.time.temporal.ChronoField.YEAR; | ||
|
||
import java.io.IOException; | ||
import java.time.DateTimeException; | ||
import java.time.YearMonth; | ||
import java.time.format.DateTimeFormatter; | ||
import java.time.format.DateTimeFormatterBuilder; | ||
import java.time.format.SignStyle; | ||
|
||
import com.fasterxml.jackson.databind.DeserializationContext; | ||
|
||
/** | ||
* @since 2.10 (had a typo previously) | ||
*/ | ||
public class YearMonthKeyDeserializer extends Jsr310KeyDeserializer { | ||
public static final YearMonthKeyDeserializer INSTANCE = new YearMonthKeyDeserializer(); | ||
|
||
// parser copied from YearMonth | ||
private static final DateTimeFormatter FORMATTER = new DateTimeFormatterBuilder() | ||
.appendValue(YEAR, 4, 10, SignStyle.EXCEEDS_PAD) | ||
.appendLiteral('-') | ||
.appendValue(MONTH_OF_YEAR, 2) | ||
.toFormatter(); | ||
|
||
protected YearMonthKeyDeserializer() { } // only protected for 2.10, to allow sub-class | ||
|
||
@Override | ||
protected YearMonth deserialize(String key, DeserializationContext ctxt) throws IOException { | ||
try { | ||
return YearMonth.parse(key, FORMATTER); | ||
} catch (DateTimeException e) { | ||
return _handleDateTimeException(ctxt, YearMonth.class, e, key); | ||
} | ||
} | ||
} |
36 changes: 6 additions & 30 deletions
36
...rc/main/java/com/fasterxml/jackson/datatype/jsr310/deser/key/YearMothKeyDeserializer.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 |
---|---|---|
@@ -1,38 +1,14 @@ | ||
package com.fasterxml.jackson.datatype.jsr310.deser.key; | ||
|
||
import static java.time.temporal.ChronoField.MONTH_OF_YEAR; | ||
import static java.time.temporal.ChronoField.YEAR; | ||
|
||
import java.io.IOException; | ||
import java.time.DateTimeException; | ||
import java.time.YearMonth; | ||
import java.time.format.DateTimeFormatter; | ||
import java.time.format.DateTimeFormatterBuilder; | ||
import java.time.format.SignStyle; | ||
|
||
import com.fasterxml.jackson.databind.DeserializationContext; | ||
|
||
public class YearMothKeyDeserializer extends Jsr310KeyDeserializer { | ||
|
||
/** | ||
* @deprecated Due to typo in class name use {@link YearMonthKeyDeserializer} instead. | ||
*/ | ||
@Deprecated // since 2.10 | ||
public class YearMothKeyDeserializer extends YearMonthKeyDeserializer { | ||
@SuppressWarnings("hiding") | ||
public static final YearMothKeyDeserializer INSTANCE = new YearMothKeyDeserializer(); | ||
|
||
// parser copied from YearMonth | ||
private static final DateTimeFormatter FORMATTER = new DateTimeFormatterBuilder() | ||
.appendValue(YEAR, 4, 10, SignStyle.EXCEEDS_PAD) | ||
.appendLiteral('-') | ||
.appendValue(MONTH_OF_YEAR, 2) | ||
.toFormatter(); | ||
|
||
private YearMothKeyDeserializer() { | ||
// singleton | ||
} | ||
|
||
@Override | ||
protected YearMonth deserialize(String key, DeserializationContext ctxt) throws IOException { | ||
try { | ||
return YearMonth.parse(key, FORMATTER); | ||
} catch (DateTimeException e) { | ||
return _handleDateTimeException(ctxt, YearMonth.class, e, key); | ||
} | ||
} | ||
} |
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