-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41 from bkenned4/master
add KeyDeserializers for LocalTime, LocalDate, & LocalDateTime
- Loading branch information
Showing
9 changed files
with
127 additions
and
33 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
22 changes: 0 additions & 22 deletions
22
src/main/java/com/fasterxml/jackson/datatype/joda/deser/DateTimeKeyDeserializer.java
This file was deleted.
Oops, something went wrong.
17 changes: 17 additions & 0 deletions
17
src/main/java/com/fasterxml/jackson/datatype/joda/deser/key/DateTimeKeyDeserializer.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,17 @@ | ||
package com.fasterxml.jackson.datatype.joda.deser.key; | ||
|
||
import java.io.IOException; | ||
|
||
import org.joda.time.*; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.DeserializationContext; | ||
|
||
public class DateTimeKeyDeserializer extends JodaKeyDeserializer { | ||
|
||
@Override | ||
protected DateTime deserialize(String key, DeserializationContext ctxt) throws IOException, JsonProcessingException{ | ||
return new DateTime(key, DateTimeZone.forTimeZone(ctxt.getTimeZone())); | ||
} | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/com/fasterxml/jackson/datatype/joda/deser/key/JodaKeyDeserializer.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,21 @@ | ||
package com.fasterxml.jackson.datatype.joda.deser.key; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.DeserializationContext; | ||
import com.fasterxml.jackson.databind.KeyDeserializer; | ||
|
||
import java.io.IOException; | ||
|
||
abstract class JodaKeyDeserializer extends KeyDeserializer { | ||
private static final long serialVersionUID = 1L; | ||
|
||
@Override | ||
public final Object deserializeKey(String key, DeserializationContext ctxt) throws IOException, JsonProcessingException { | ||
if (key.length() == 0) { // [JACKSON-360] | ||
return null; | ||
} | ||
return deserialize(key, ctxt); | ||
} | ||
|
||
protected abstract Object deserialize(String key, DeserializationContext ctxt) throws IOException, JsonProcessingException; | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/com/fasterxml/jackson/datatype/joda/deser/key/LocalDateKeyDeserializer.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,18 @@ | ||
package com.fasterxml.jackson.datatype.joda.deser.key; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.DeserializationContext; | ||
import org.joda.time.LocalDate; | ||
import org.joda.time.format.DateTimeFormatter; | ||
import org.joda.time.format.ISODateTimeFormat; | ||
|
||
import java.io.IOException; | ||
|
||
public class LocalDateKeyDeserializer extends JodaKeyDeserializer { | ||
private static final DateTimeFormatter parser = ISODateTimeFormat.localDateParser(); | ||
|
||
@Override | ||
protected LocalDate deserialize(String key, DeserializationContext ctxt) throws IOException, JsonProcessingException { | ||
return parser.parseLocalDate(key); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
...main/java/com/fasterxml/jackson/datatype/joda/deser/key/LocalDateTimeKeyDeserializer.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,18 @@ | ||
package com.fasterxml.jackson.datatype.joda.deser.key; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.DeserializationContext; | ||
import org.joda.time.LocalDateTime; | ||
import org.joda.time.format.DateTimeFormatter; | ||
import org.joda.time.format.ISODateTimeFormat; | ||
|
||
import java.io.IOException; | ||
|
||
public class LocalDateTimeKeyDeserializer extends JodaKeyDeserializer { | ||
private static final DateTimeFormatter parser = ISODateTimeFormat.localDateOptionalTimeParser(); | ||
|
||
@Override | ||
protected LocalDateTime deserialize(String key, DeserializationContext ctxt) throws IOException, JsonProcessingException { | ||
return parser.parseLocalDateTime(key); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/com/fasterxml/jackson/datatype/joda/deser/key/LocalTimeKeyDeserializer.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,18 @@ | ||
package com.fasterxml.jackson.datatype.joda.deser.key; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.DeserializationContext; | ||
import org.joda.time.LocalTime; | ||
import org.joda.time.format.DateTimeFormatter; | ||
import org.joda.time.format.ISODateTimeFormat; | ||
|
||
import java.io.IOException; | ||
|
||
public class LocalTimeKeyDeserializer extends JodaKeyDeserializer { | ||
private static final DateTimeFormatter parser = ISODateTimeFormat.localTimeParser(); | ||
|
||
@Override | ||
protected LocalTime deserialize(String key, DeserializationContext ctxt) throws IOException, JsonProcessingException { | ||
return parser.parseLocalTime(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
11 changes: 4 additions & 7 deletions
11
src/test/java/com/fasterxml/jackson/datatype/joda/JodaTestBase.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