diff --git a/release-notes/CREDITS b/release-notes/CREDITS index 27d1adfd..eae5873c 100644 --- a/release-notes/CREDITS +++ b/release-notes/CREDITS @@ -12,11 +12,15 @@ ncjones@github.com: * Suggested #23: package as a bundle (2.3.1) -Lorcan C: +Lorcan C * Contributed #25: Add `KeyDeserializer` for `DateTime` (2.3.1) -Hendy Irawan: (ceefour@github) +Hendy Irawan (ceefour@github) * Contributed #27: Allow support for `DateTimeZone` (2.3.1) +Brad Kennedy (bkenned4@github) + * Contributed #45: Can't use LocalTime, LocalDate & LocalDateTime as Key type for a Map + (2.4.3) + diff --git a/release-notes/VERSION b/release-notes/VERSION index c83243d4..19e46b9f 100644 --- a/release-notes/VERSION +++ b/release-notes/VERSION @@ -1,12 +1,19 @@ Project: jackson-datatype-joda -Version: 2.4.2 (15-Aug-2014) +Version: 2.4.3 (xx-xxx-2014) -No changes since 2.4.0 +#41: Can't use LocalTime, LocalDate & LocalDateTime as Key type for a Map + (contributed by Brad K, reported by Guido M) +#46: Interval deserialization fails for negative start instants + (reported by Dan G, dgrabows@github) ------------------------------------------------------------------------ === History: === ------------------------------------------------------------------------ +2.4.2 (15-Aug-2014) + +No changes since 2.4.0 + 2.4.1 (17-Jun-2014) No changes since 2.4.0 diff --git a/src/main/java/com/fasterxml/jackson/datatype/joda/deser/IntervalDeserializer.java b/src/main/java/com/fasterxml/jackson/datatype/joda/deser/IntervalDeserializer.java index 6d5e4adc..d902096e 100644 --- a/src/main/java/com/fasterxml/jackson/datatype/joda/deser/IntervalDeserializer.java +++ b/src/main/java/com/fasterxml/jackson/datatype/joda/deser/IntervalDeserializer.java @@ -4,6 +4,8 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonToken; import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonMappingException; + import org.joda.time.Interval; import java.io.IOException; @@ -19,13 +21,26 @@ public IntervalDeserializer() { @Override public Interval deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException { - if (jsonParser.getCurrentToken() == JsonToken.VALUE_STRING) { - String v = jsonParser.getText(); - int dashIndex = v.indexOf('-'); - long start = Long.valueOf(v.substring(0, dashIndex)); - long end = Long.valueOf(v.substring(dashIndex + 1)); - return new Interval(start, end); + JsonToken t = jsonParser.getCurrentToken(); + if (t != JsonToken.VALUE_STRING) { + throw deserializationContext.mappingException("expected JSON String, got "+t); + } + String v = jsonParser.getText().trim(); + + int dashIndex = v.isEmpty() ? -1 : v.indexOf('-', 1); + if (dashIndex < 0) { + throw deserializationContext.weirdStringException(v, handledType(), "no hyphen found to separate start, end"); + } + long start, end; + String str = v.substring(0, dashIndex); + try { + start = Long.valueOf(str); + str = v.substring(dashIndex + 1); + end = Long.valueOf(str); + } catch (NumberFormatException e) { + throw JsonMappingException.from(jsonParser, + "Failed to parse number from '"+str+"' (full source String '"+v+"') to construct "+handledType().getName()); } - throw deserializationContext.mappingException("expected JSON String"); + return new Interval(start, end); } } diff --git a/src/test/java/com/fasterxml/jackson/datatype/joda/MixedListTest.java b/src/test/java/com/fasterxml/jackson/datatype/joda/MixedListTest.java index ac6a47ae..c529c968 100644 --- a/src/test/java/com/fasterxml/jackson/datatype/joda/MixedListTest.java +++ b/src/test/java/com/fasterxml/jackson/datatype/joda/MixedListTest.java @@ -14,10 +14,10 @@ public class MixedListTest extends JodaTestBase public void testMixedList() throws Exception { - final Map map = new HashMap(); - DateTime dt = new DateTime(DateTimeZone.UTC); - map.put("A", dt); - map.put("B", 0); + final Map map = new HashMap(); + DateTime dt = new DateTime(DateTimeZone.UTC); + map.put("A", dt); + map.put("B", 0); final String json = MAPPER.writeValueAsString(map); // by default, timestamps should come out as longs... @@ -29,14 +29,14 @@ public void testMixedList() throws Exception Object obB = result.get("B"); assertNotNull(obB); if (!(obB instanceof Number)) { - fail("Expected 'B' to be a Number; instead of value of type "+obB.getClass().getName()); + fail("Expected 'B' to be a Number; instead of value of type "+obB.getClass().getName()); } assertEquals(Integer.valueOf(0), result.get("B")); Object obA = result.get("A"); assertNotNull(obA); if (!(obA instanceof Number)) { - fail("Expected 'A' to be a number; instead of value of type "+obA.getClass().getName()); + fail("Expected 'A' to be a number; instead of value of type "+obA.getClass().getName()); } } } diff --git a/src/test/java/com/fasterxml/jackson/datatype/joda/JodaDeserializationTest.java b/src/test/java/com/fasterxml/jackson/datatype/joda/deser/MiscDeserializationTest.java similarity index 98% rename from src/test/java/com/fasterxml/jackson/datatype/joda/JodaDeserializationTest.java rename to src/test/java/com/fasterxml/jackson/datatype/joda/deser/MiscDeserializationTest.java index 909bcb64..20209e1e 100644 --- a/src/test/java/com/fasterxml/jackson/datatype/joda/JodaDeserializationTest.java +++ b/src/test/java/com/fasterxml/jackson/datatype/joda/deser/MiscDeserializationTest.java @@ -1,10 +1,12 @@ -package com.fasterxml.jackson.datatype.joda; +package com.fasterxml.jackson.datatype.joda.deser; import com.fasterxml.jackson.annotation.JsonTypeInfo; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.datatype.joda.JodaTestBase; + import org.joda.time.*; import java.io.IOException; @@ -18,7 +20,7 @@ * Basic support is added for handling {@link DateTime}; more can be * added over time if and when requested. */ -public class JodaDeserializationTest extends JodaTestBase +public class MiscDeserializationTest extends JodaTestBase { /* /********************************************************** @@ -236,6 +238,10 @@ public void testIntervalDeser() throws IOException Interval interval = MAPPER.readValue(quote("1396439982-1396440001"), Interval.class); assertEquals(1396439982, interval.getStartMillis()); assertEquals(1396440001, interval.getEndMillis()); + + interval = MAPPER.readValue(quote("-100-1396440001"), Interval.class); + assertEquals(-100, interval.getStartMillis()); + assertEquals(1396440001, interval.getEndMillis()); } public void testIntervalDeserWithTypeInfo() throws IOException