Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ public JodaModule()
addKeyDeserializer(LocalTime.class, new LocalTimeKeyDeserializer());
addKeyDeserializer(LocalDate.class, new LocalDateKeyDeserializer());
addKeyDeserializer(LocalDateTime.class, new LocalDateTimeKeyDeserializer());
addKeyDeserializer(Duration.class, new DurationKeyDeserializer());
addKeyDeserializer(Period.class, new PeriodKeyDeserializer());

// 26-Dec-2015, tatu: Joda has deprecated following types:

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.fasterxml.jackson.datatype.joda.deser.key;

import com.fasterxml.jackson.databind.DeserializationContext;
import org.joda.time.Duration;

import java.io.IOException;

public class DurationKeyDeserializer extends JodaKeyDeserializer {
private static final long serialVersionUID = 1L;

@Override
protected Duration deserialize(String key, DeserializationContext ctxt) throws IOException {
return Duration.parse(key);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.fasterxml.jackson.datatype.joda.deser.key;

import com.fasterxml.jackson.databind.DeserializationContext;
import org.joda.time.Period;

import java.io.IOException;

public class PeriodKeyDeserializer extends JodaKeyDeserializer {
private static final long serialVersionUID = 1L;

@Override
protected Period deserialize(String key, DeserializationContext ctxt) throws IOException {
return Period.parse(key);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,20 @@ public void testLocalDateTimeKeyDeserialize() throws IOException {
assertNotNull(map);
assertTrue(map.containsKey(LocalDateTime.parse("2014-05-23T00:00:00.000")));
}
public void testDurationKeyDeserialize() throws IOException {

final String json = "{" + quote("PT60s") + ":0}";
final Map<Duration, Long> map = MAPPER.readValue(json, new TypeReference<Map<Duration, String>>() { });
assertNotNull(map);
assertTrue(map.containsKey(Duration.standardMinutes(1L)));
}
public void testPeriodKeyDeserialize() throws IOException {

final String json = "{" + quote("PT1H2M3.004S") + ":0}";
final Map<Period, Long> map = MAPPER.readValue(json, new TypeReference<Map<Period, String>>() { });
assertNotNull(map);
assertTrue(map.containsKey(new Period(1, 2, 3, 4)));
}

public void testDeserMonthDay() throws Exception
{
Expand Down