diff --git a/src/main/java/com/fasterxml/jackson/datatype/jsr310/JSR310Module.java b/src/main/java/com/fasterxml/jackson/datatype/jsr310/JSR310Module.java
index 60afbb32..8f5fd4e6 100644
--- a/src/main/java/com/fasterxml/jackson/datatype/jsr310/JSR310Module.java
+++ b/src/main/java/com/fasterxml/jackson/datatype/jsr310/JSR310Module.java
@@ -49,6 +49,7 @@
import com.fasterxml.jackson.datatype.jsr310.deser.LocalTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.deser.OffsetTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.deser.YearDeserializer;
+import com.fasterxml.jackson.datatype.jsr310.deser.YearMonthDeserializer;
import com.fasterxml.jackson.datatype.jsr310.deser.key.DurationKeyDeserializer;
import com.fasterxml.jackson.datatype.jsr310.deser.key.InstantKeyDeserializer;
import com.fasterxml.jackson.datatype.jsr310.deser.key.LocalDateKeyDeserializer;
@@ -63,7 +64,6 @@
import com.fasterxml.jackson.datatype.jsr310.deser.key.ZoneIdKeyDeserializer;
import com.fasterxml.jackson.datatype.jsr310.deser.key.ZoneOffsetKeyDeserializer;
import com.fasterxml.jackson.datatype.jsr310.deser.key.ZonedDateTimeKeyDeserializer;
-import com.fasterxml.jackson.datatype.jsr310.deser.YearMonthDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.DurationSerializer;
import com.fasterxml.jackson.datatype.jsr310.ser.InstantSerializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer;
@@ -71,9 +71,9 @@
import com.fasterxml.jackson.datatype.jsr310.ser.LocalTimeSerializer;
import com.fasterxml.jackson.datatype.jsr310.ser.OffsetDateTimeSerializer;
import com.fasterxml.jackson.datatype.jsr310.ser.OffsetTimeSerializer;
-import com.fasterxml.jackson.datatype.jsr310.ser.YearSerializer;
import com.fasterxml.jackson.datatype.jsr310.ser.YearMonthSerializer;
-import com.fasterxml.jackson.datatype.jsr310.ser.ZonedDateTimeSerializer;
+import com.fasterxml.jackson.datatype.jsr310.ser.YearSerializer;
+import com.fasterxml.jackson.datatype.jsr310.ser.ZonedDateTimeWithZoneIdSerializer;
import com.fasterxml.jackson.datatype.jsr310.ser.key.ZonedDateTimeKeySerializer;
/**
@@ -119,10 +119,14 @@
*
{@link LocalDate}, {@link LocalTime}, {@link LocalDateTime}, and {@link OffsetTime}, which cannot portably be
* converted to timestamps and are instead represented as arrays when WRITE_DATES_AS_TIMESTAMPS is enabled.
*
+ *
+ * This module is soon to be deprecated: the module has a backwards incompatible behavioural change: default preference is to serialize
+ * temporal values strictly according to ISO-8601 standards. Please start using {@link JavaTimeModule} instead.
*
* @author Nick Williams
* @since 2.2.0
* @see com.fasterxml.jackson.datatype.jsr310.ser.key.Jsr310NullKeySerializer
+ * @see com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
*/
public final class JSR310Module extends SimpleModule
{
@@ -161,10 +165,10 @@ public JSR310Module()
addSerializer(Period.class, new ToStringSerializer(Period.class));
addSerializer(Year.class, YearSerializer.INSTANCE);
addSerializer(YearMonth.class, YearMonthSerializer.INSTANCE);
- addSerializer(ZonedDateTime.class, ZonedDateTimeSerializer.INSTANCE);
+ addSerializer(ZonedDateTime.class, ZonedDateTimeWithZoneIdSerializer.INSTANCE);
// note: actual concrete type is `ZoneRegion`, but that's not visible:
addSerializer(ZoneId.class, new ToStringSerializer(ZoneId.class));
-
+
addSerializer(ZoneOffset.class, new ToStringSerializer(ZoneOffset.class));
// key serializers
diff --git a/src/main/java/com/fasterxml/jackson/datatype/jsr310/JavaTimeModule.java b/src/main/java/com/fasterxml/jackson/datatype/jsr310/JavaTimeModule.java
new file mode 100644
index 00000000..4ba35ba6
--- /dev/null
+++ b/src/main/java/com/fasterxml/jackson/datatype/jsr310/JavaTimeModule.java
@@ -0,0 +1,244 @@
+/*
+ * Copyright 2013 FasterXML.com
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may
+ * not use this file except in compliance with the License. You may obtain
+ * a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+
+package com.fasterxml.jackson.datatype.jsr310;
+
+import java.time.Duration;
+import java.time.Instant;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.LocalTime;
+import java.time.MonthDay;
+import java.time.OffsetDateTime;
+import java.time.OffsetTime;
+import java.time.Period;
+import java.time.Year;
+import java.time.YearMonth;
+import java.time.ZoneId;
+import java.time.ZoneOffset;
+import java.time.ZonedDateTime;
+
+import com.fasterxml.jackson.core.Version;
+import com.fasterxml.jackson.databind.BeanDescription;
+import com.fasterxml.jackson.databind.DeserializationConfig;
+import com.fasterxml.jackson.databind.deser.ValueInstantiator;
+import com.fasterxml.jackson.databind.deser.ValueInstantiators;
+import com.fasterxml.jackson.databind.deser.std.StdValueInstantiator;
+import com.fasterxml.jackson.databind.introspect.AnnotatedClass;
+import com.fasterxml.jackson.databind.introspect.AnnotatedMethod;
+import com.fasterxml.jackson.databind.module.SimpleModule;
+import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
+import com.fasterxml.jackson.datatype.jsr310.deser.DurationDeserializer;
+import com.fasterxml.jackson.datatype.jsr310.deser.InstantDeserializer;
+import com.fasterxml.jackson.datatype.jsr310.deser.JSR310StringParsableDeserializer;
+import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer;
+import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
+import com.fasterxml.jackson.datatype.jsr310.deser.LocalTimeDeserializer;
+import com.fasterxml.jackson.datatype.jsr310.deser.OffsetTimeDeserializer;
+import com.fasterxml.jackson.datatype.jsr310.deser.YearDeserializer;
+import com.fasterxml.jackson.datatype.jsr310.deser.YearMonthDeserializer;
+import com.fasterxml.jackson.datatype.jsr310.deser.key.DurationKeyDeserializer;
+import com.fasterxml.jackson.datatype.jsr310.deser.key.InstantKeyDeserializer;
+import com.fasterxml.jackson.datatype.jsr310.deser.key.LocalDateKeyDeserializer;
+import com.fasterxml.jackson.datatype.jsr310.deser.key.LocalDateTimeKeyDeserializer;
+import com.fasterxml.jackson.datatype.jsr310.deser.key.LocalTimeKeyDeserializer;
+import com.fasterxml.jackson.datatype.jsr310.deser.key.MonthDayKeyDeserializer;
+import com.fasterxml.jackson.datatype.jsr310.deser.key.OffsetDateTimeKeyDeserializer;
+import com.fasterxml.jackson.datatype.jsr310.deser.key.OffsetTimeKeyDeserializer;
+import com.fasterxml.jackson.datatype.jsr310.deser.key.PeriodKeyDeserializer;
+import com.fasterxml.jackson.datatype.jsr310.deser.key.YearKeyDeserializer;
+import com.fasterxml.jackson.datatype.jsr310.deser.key.YearMothKeyDeserializer;
+import com.fasterxml.jackson.datatype.jsr310.deser.key.ZoneIdKeyDeserializer;
+import com.fasterxml.jackson.datatype.jsr310.deser.key.ZoneOffsetKeyDeserializer;
+import com.fasterxml.jackson.datatype.jsr310.deser.key.ZonedDateTimeKeyDeserializer;
+import com.fasterxml.jackson.datatype.jsr310.ser.DurationSerializer;
+import com.fasterxml.jackson.datatype.jsr310.ser.InstantSerializer;
+import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer;
+import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
+import com.fasterxml.jackson.datatype.jsr310.ser.LocalTimeSerializer;
+import com.fasterxml.jackson.datatype.jsr310.ser.OffsetDateTimeSerializer;
+import com.fasterxml.jackson.datatype.jsr310.ser.OffsetTimeSerializer;
+import com.fasterxml.jackson.datatype.jsr310.ser.YearMonthSerializer;
+import com.fasterxml.jackson.datatype.jsr310.ser.YearSerializer;
+import com.fasterxml.jackson.datatype.jsr310.ser.ZonedDateTimeSerializer;
+import com.fasterxml.jackson.datatype.jsr310.ser.key.ZonedDateTimeKeySerializer;
+
+// TODO ObjectMapper.findAndRegisterModules() is unsupported at the moment by this module
+
+/**
+ * Class that registers capability of serializing {@code java.time} objects with the Jackson core.
+ *
+ *
+ * ObjectMapper mapper = new ObjectMapper();
+ * mapper.registerModule(new JavaTimeModule());
+ *
+ *
+ * Most {@code java.time} types are serialized as numbers (integers or decimals as appropriate) if the
+ * {@link com.fasterxml.jackson.databind.SerializationFeature#WRITE_DATES_AS_TIMESTAMPS} feature is enabled, and otherwise are serialized in
+ * standard ISO-8601 string representation. ISO-8601 specifies formats
+ * for representing offset dates and times, zoned dates and times, local dates and times, periods, durations, zones, and more. All
+ * {@code java.time} types have built-in translation to and from ISO-8601 formats.
+ *
+ * Granularity of timestamps is controlled through the companion features
+ * {@link com.fasterxml.jackson.databind.SerializationFeature#WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS} and
+ * {@link com.fasterxml.jackson.databind.DeserializationFeature#READ_DATE_TIMESTAMPS_AS_NANOSECONDS}. For serialization, timestamps are
+ * written as fractional numbers (decimals), where the number is seconds and the decimal is fractional seconds, if
+ * {@code WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS} is enabled (it is by default), with resolution as fine as nanoseconds depending on the
+ * underlying JDK implementation. If {@code WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS} is disabled, timestamps are written as a whole number of
+ * milliseconds. At deserialization time, decimal numbers are always read as fractional second timestamps with up-to-nanosecond resolution,
+ * since the meaning of the decimal is unambiguous. The more ambiguous integer types are read as fractional seconds without a decimal point
+ * if {@code READ_DATE_TIMESTAMPS_AS_NANOSECONDS} is enabled (it is by default), and otherwise they are read as milliseconds.
+ *
+ * Some exceptions to this standard serialization/deserialization rule:
+ *
+ * - {@link Period}, which always results in an ISO-8601 format because Periods must be represented in years, months, and/or days.
+ * - {@link Year}, which only contains a year and cannot be represented with a timestamp.
+ * - {@link YearMonth}, which only contains a year and a month and cannot be represented with a timestamp.
+ * - {@link MonthDay}, which only contains a month and a day and cannot be represented with a timestamp.
+ * - {@link ZoneId} and {@link ZoneOffset}, which do not actually store dates and times but are supported with this module nonetheless.
+ * - {@link LocalDate}, {@link LocalTime}, {@link LocalDateTime}, and {@link OffsetTime}, which cannot portably be converted to timestamps
+ * and are instead represented as arrays when WRITE_DATES_AS_TIMESTAMPS is enabled.
+ *
+ *
+ * @author Nick Williams
+ * @author Zoltan Kiss
+ * @since 2.6.0
+ * @see com.fasterxml.jackson.datatype.jsr310.ser.key.Jsr310NullKeySerializer
+ */
+public final class JavaTimeModule extends SimpleModule
+{
+ private static final long serialVersionUID = 1L;
+
+ public JavaTimeModule()
+ {
+ super(Version.unknownVersion()); // !!! TEST
+ // super(PackageVersion.VERSION);
+
+ // first deserializers
+ addDeserializer(Duration.class, DurationDeserializer.INSTANCE);
+ addDeserializer(Instant.class, InstantDeserializer.INSTANT);
+ addDeserializer(LocalDateTime.class, LocalDateTimeDeserializer.INSTANCE);
+ addDeserializer(LocalDate.class, LocalDateDeserializer.INSTANCE);
+ addDeserializer(LocalTime.class, LocalTimeDeserializer.INSTANCE);
+ addDeserializer(MonthDay.class, JSR310StringParsableDeserializer.MONTH_DAY);
+ addDeserializer(OffsetDateTime.class, InstantDeserializer.OFFSET_DATE_TIME);
+ addDeserializer(OffsetTime.class, OffsetTimeDeserializer.INSTANCE);
+ addDeserializer(Period.class, JSR310StringParsableDeserializer.PERIOD);
+ addDeserializer(Year.class, YearDeserializer.INSTANCE);
+ addDeserializer(YearMonth.class, YearMonthDeserializer.INSTANCE);
+ addDeserializer(ZonedDateTime.class, InstantDeserializer.ZONED_DATE_TIME);
+ addDeserializer(ZoneId.class, JSR310StringParsableDeserializer.ZONE_ID);
+ addDeserializer(ZoneOffset.class, JSR310StringParsableDeserializer.ZONE_OFFSET);
+
+ // then serializers:
+ addSerializer(Duration.class, DurationSerializer.INSTANCE);
+ addSerializer(Instant.class, InstantSerializer.INSTANCE);
+ addSerializer(LocalDateTime.class, LocalDateTimeSerializer.INSTANCE);
+ addSerializer(LocalDate.class, LocalDateSerializer.INSTANCE);
+ addSerializer(LocalTime.class, LocalTimeSerializer.INSTANCE);
+ addSerializer(MonthDay.class, new ToStringSerializer(MonthDay.class));
+ addSerializer(OffsetDateTime.class, OffsetDateTimeSerializer.INSTANCE);
+ addSerializer(OffsetTime.class, OffsetTimeSerializer.INSTANCE);
+ addSerializer(Period.class, new ToStringSerializer(Period.class));
+ addSerializer(Year.class, YearSerializer.INSTANCE);
+ addSerializer(YearMonth.class, YearMonthSerializer.INSTANCE);
+ addSerializer(ZonedDateTime.class, ZonedDateTimeSerializer.INSTANCE);
+ // note: actual concrete type is `ZoneRegion`, but that's not visible:
+ addSerializer(ZoneId.class, new ToStringSerializer(ZoneId.class));
+
+ addSerializer(ZoneOffset.class, new ToStringSerializer(ZoneOffset.class));
+
+ // key serializers
+ addKeySerializer(ZonedDateTime.class, ZonedDateTimeKeySerializer.INSTANCE);
+
+ // key deserializers
+ addKeyDeserializer(Duration.class, DurationKeyDeserializer.INSTANCE);
+ addKeyDeserializer(Instant.class, InstantKeyDeserializer.INSTANCE);
+ addKeyDeserializer(LocalDateTime.class, LocalDateTimeKeyDeserializer.INSTANCE);
+ addKeyDeserializer(LocalDate.class, LocalDateKeyDeserializer.INSTANCE);
+ addKeyDeserializer(LocalTime.class, LocalTimeKeyDeserializer.INSTANCE);
+ addKeyDeserializer(MonthDay.class, MonthDayKeyDeserializer.INSTANCE);
+ addKeyDeserializer(OffsetDateTime.class, OffsetDateTimeKeyDeserializer.INSTANCE);
+ addKeyDeserializer(OffsetTime.class, OffsetTimeKeyDeserializer.INSTANCE);
+ addKeyDeserializer(Period.class, PeriodKeyDeserializer.INSTANCE);
+ addKeyDeserializer(Year.class, YearKeyDeserializer.INSTANCE);
+ addKeyDeserializer(YearMonth.class, YearMothKeyDeserializer.INSTANCE);
+ addKeyDeserializer(ZonedDateTime.class, ZonedDateTimeKeyDeserializer.INSTANCE);
+ addKeyDeserializer(ZoneId.class, ZoneIdKeyDeserializer.INSTANCE);
+ addKeyDeserializer(ZoneOffset.class, ZoneOffsetKeyDeserializer.INSTANCE);
+ }
+
+ @Override
+ public void setupModule(SetupContext context) {
+ super.setupModule(context);
+ context.addValueInstantiators(new ValueInstantiators.Base() {
+ @Override
+ public ValueInstantiator findValueInstantiator(DeserializationConfig config,
+ BeanDescription beanDesc, ValueInstantiator defaultInstantiator)
+ {
+ Class> raw = beanDesc.getBeanClass();
+ // 15-May-2015, tatu: In theory not safe, but in practice we do need to do "fuzzy" matching
+ // because we will (for now) be getting a subtype, but in future may want to downgrade
+ // to the common base type. Even more, serializer may purposefully force use of base type.
+ // So... in practice it really should always work, in the end. :)
+ if (ZoneId.class.isAssignableFrom(raw)) {
+ // let's assume we should be getting "empty" StdValueInstantiator here:
+ if (defaultInstantiator instanceof StdValueInstantiator) {
+ StdValueInstantiator inst = (StdValueInstantiator) defaultInstantiator;
+ // one further complication: we need ZoneId info, not sub-class
+ AnnotatedClass ac;
+ if (raw == ZoneId.class) {
+ ac = beanDesc.getClassInfo();
+ } else {
+ // we don't need Annotations, so constructing directly is fine here
+ // even if it's not generally recommended
+ ac = AnnotatedClass.construct(ZoneId.class, null, null);
+ }
+ if (!inst.canCreateFromString()) {
+ AnnotatedMethod factory = _findFactory(ac, "of", String.class);
+ if (factory != null) {
+ inst.configureFromStringCreator(factory);
+ }
+ // otherwise... should we indicate an error?
+ }
+ // return ZoneIdInstantiator.construct(config, beanDesc, defaultInstantiator);
+ }
+ }
+ return defaultInstantiator;
+ }
+ });
+ }
+
+ // For
+ protected AnnotatedMethod _findFactory(AnnotatedClass cls, String name, Class>... argTypes)
+ {
+ final int argCount = argTypes.length;
+ for (AnnotatedMethod method : cls.getStaticMethods()) {
+ if (!name.equals(method.getName())
+ || (method.getParameterCount() != argCount)) {
+ continue;
+ }
+ for (int i = 0; i < argCount; ++i) {
+ Class> argType = method.getParameter(i).getRawType();
+ if (!argType.isAssignableFrom(argTypes[i])) {
+ continue;
+ }
+ }
+ return method;
+ }
+ return null;
+ }
+}
diff --git a/src/main/java/com/fasterxml/jackson/datatype/jsr310/ser/InstantSerializerBase.java b/src/main/java/com/fasterxml/jackson/datatype/jsr310/ser/InstantSerializerBase.java
index d9643e41..4e553912 100644
--- a/src/main/java/com/fasterxml/jackson/datatype/jsr310/ser/InstantSerializerBase.java
+++ b/src/main/java/com/fasterxml/jackson/datatype/jsr310/ser/InstantSerializerBase.java
@@ -23,6 +23,7 @@
import java.io.IOException;
import java.time.temporal.Temporal;
+import java.util.function.Function;
import java.util.function.ToIntFunction;
import java.util.function.ToLongFunction;
@@ -39,13 +40,23 @@ public class InstantSerializerBase extends JSR310SerializerB
private final ToIntFunction getNanoseconds;
+ private final Function toIsoString;
+
+ protected InstantSerializerBase(Class supportedType, ToLongFunction getEpochMillis,
+ ToLongFunction getEpochSeconds, ToIntFunction getNanoseconds)
+ {
+ this(supportedType, getEpochMillis, getEpochSeconds, getNanoseconds, Object::toString);
+ }
+
protected InstantSerializerBase(Class supportedType, ToLongFunction getEpochMillis,
- ToLongFunction getEpochSeconds, ToIntFunction getNanoseconds)
+ ToLongFunction getEpochSeconds, ToIntFunction getNanoseconds,
+ Function toIsoString)
{
super(supportedType);
this.getEpochMillis = getEpochMillis;
this.getEpochSeconds = getEpochSeconds;
this.getNanoseconds = getNanoseconds;
+ this.toIsoString = toIsoString;
}
@Override
@@ -68,7 +79,7 @@ public void serialize(T instant, JsonGenerator generator, SerializerProvider pro
}
else
{
- generator.writeString(instant.toString());
+ generator.writeString(this.toIsoString.apply(instant));
}
}
}
diff --git a/src/main/java/com/fasterxml/jackson/datatype/jsr310/ser/OffsetDateTimeSerializer.java b/src/main/java/com/fasterxml/jackson/datatype/jsr310/ser/OffsetDateTimeSerializer.java
index 5d7d5f13..733a016b 100644
--- a/src/main/java/com/fasterxml/jackson/datatype/jsr310/ser/OffsetDateTimeSerializer.java
+++ b/src/main/java/com/fasterxml/jackson/datatype/jsr310/ser/OffsetDateTimeSerializer.java
@@ -1,6 +1,7 @@
package com.fasterxml.jackson.datatype.jsr310.ser;
import java.time.OffsetDateTime;
+import java.time.format.DateTimeFormatter;
public class OffsetDateTimeSerializer extends InstantSerializerBase
{
@@ -10,6 +11,7 @@ public class OffsetDateTimeSerializer extends InstantSerializerBase dt.toInstant().toEpochMilli(),
- OffsetDateTime::toEpochSecond, OffsetDateTime::getNano);
+ OffsetDateTime::toEpochSecond, OffsetDateTime::getNano,
+ DateTimeFormatter.ISO_OFFSET_DATE_TIME::format);
}
}
diff --git a/src/main/java/com/fasterxml/jackson/datatype/jsr310/ser/ZonedDateTimeSerializer.java b/src/main/java/com/fasterxml/jackson/datatype/jsr310/ser/ZonedDateTimeSerializer.java
index c7977dff..d6a6ce1c 100644
--- a/src/main/java/com/fasterxml/jackson/datatype/jsr310/ser/ZonedDateTimeSerializer.java
+++ b/src/main/java/com/fasterxml/jackson/datatype/jsr310/ser/ZonedDateTimeSerializer.java
@@ -1,6 +1,7 @@
package com.fasterxml.jackson.datatype.jsr310.ser;
import java.time.ZonedDateTime;
+import java.time.format.DateTimeFormatter;
public class ZonedDateTimeSerializer extends InstantSerializerBase
{
@@ -10,6 +11,8 @@ public class ZonedDateTimeSerializer extends InstantSerializerBase dt.toInstant().toEpochMilli(),
- ZonedDateTime::toEpochSecond, ZonedDateTime::getNano);
+ ZonedDateTime::toEpochSecond, ZonedDateTime::getNano,
+ // ISO_ZONED_DATE_TIME is not the ISO format, it is an extension of it
+ DateTimeFormatter.ISO_OFFSET_DATE_TIME::format);
}
}
diff --git a/src/main/java/com/fasterxml/jackson/datatype/jsr310/ser/ZonedDateTimeWithZoneIdSerializer.java b/src/main/java/com/fasterxml/jackson/datatype/jsr310/ser/ZonedDateTimeWithZoneIdSerializer.java
new file mode 100644
index 00000000..478fb272
--- /dev/null
+++ b/src/main/java/com/fasterxml/jackson/datatype/jsr310/ser/ZonedDateTimeWithZoneIdSerializer.java
@@ -0,0 +1,19 @@
+package com.fasterxml.jackson.datatype.jsr310.ser;
+
+import java.time.ZonedDateTime;
+
+// TODO deprecate this: SerializationFeature config should be respected, default behaviour should be to
+// serialize according to ISO-8601 format
+public class ZonedDateTimeWithZoneIdSerializer extends InstantSerializerBase
+{
+ private static final long serialVersionUID = 1L;
+
+ public static final ZonedDateTimeWithZoneIdSerializer INSTANCE = new ZonedDateTimeWithZoneIdSerializer();
+
+ protected ZonedDateTimeWithZoneIdSerializer() {
+ super(ZonedDateTime.class, dt -> dt.toInstant().toEpochMilli(),
+ ZonedDateTime::toEpochSecond, ZonedDateTime::getNano,
+ // Serialize in a backwards compatible way: with zone id, using toString method
+ Object::toString);
+ }
+}
diff --git a/src/test/java/com/fasterxml/jackson/datatype/jsr310/ModuleTestBase.java b/src/test/java/com/fasterxml/jackson/datatype/jsr310/ModuleTestBase.java
index fcb773f9..1e5bf8bb 100644
--- a/src/test/java/com/fasterxml/jackson/datatype/jsr310/ModuleTestBase.java
+++ b/src/test/java/com/fasterxml/jackson/datatype/jsr310/ModuleTestBase.java
@@ -6,6 +6,6 @@ public class ModuleTestBase
{
protected ObjectMapper newMapper() {
return new ObjectMapper()
- .registerModule(new JSR310Module());
+ .registerModule(new JavaTimeModule());
}
}
diff --git a/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestDurationKeySerialization.java b/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestDurationKeySerialization.java
index 7cc9e6db..009c5b74 100644
--- a/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestDurationKeySerialization.java
+++ b/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestDurationKeySerialization.java
@@ -24,7 +24,7 @@ public class TestDurationKeySerialization {
@Before
public void setUp() {
this.om = new ObjectMapper();
- om.registerModule(new JSR310Module());
+ om.registerModule(new JavaTimeModule());
map = new HashMap<>();
}
diff --git a/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestInstantKeySerialization.java b/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestInstantKeySerialization.java
index 3cfc6b75..1ba54c8f 100644
--- a/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestInstantKeySerialization.java
+++ b/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestInstantKeySerialization.java
@@ -27,7 +27,7 @@ public class TestInstantKeySerialization {
@Before
public void setUp() {
this.om = new ObjectMapper();
- om.registerModule(new JSR310Module());
+ om.registerModule(new JavaTimeModule());
map = new HashMap<>();
}
diff --git a/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestInstantSerialization.java b/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestInstantSerialization.java
index b6e336fb..ae397959 100644
--- a/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestInstantSerialization.java
+++ b/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestInstantSerialization.java
@@ -16,27 +16,32 @@
package com.fasterxml.jackson.datatype.jsr310;
-import com.fasterxml.jackson.databind.DeserializationFeature;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.SerializationFeature;
-import org.junit.Before;
-import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
import java.time.Instant;
+import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.time.temporal.Temporal;
-import static org.junit.Assert.*;
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.SerializationFeature;
+import org.junit.Before;
+import org.junit.Test;
public class TestInstantSerialization
{
+ private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ISO_INSTANT;
+
private ObjectMapper mapper;
@Before
public void setUp()
{
this.mapper = new ObjectMapper();
- this.mapper.registerModule(new JSR310Module());
+ this.mapper.registerModule(new JavaTimeModule());
}
@Test
@@ -126,7 +131,7 @@ public void testSerializationAsString01() throws Exception
String value = this.mapper.writeValueAsString(date);
assertNotNull("The value should not be null.", value);
- assertEquals("The value is not correct.", '"' + date.toString() + '"', value);
+ assertEquals("The value is not correct.", '"' + FORMATTER.format(date) + '"', value);
}
@Test
@@ -138,7 +143,7 @@ public void testSerializationAsString02() throws Exception
String value = this.mapper.writeValueAsString(date);
assertNotNull("The value should not be null.", value);
- assertEquals("The value is not correct.", '"' + date.toString() + '"', value);
+ assertEquals("The value is not correct.", '"' + FORMATTER.format(date) + '"', value);
}
@Test
@@ -150,7 +155,7 @@ public void testSerializationAsString03() throws Exception
String value = this.mapper.writeValueAsString(date);
assertNotNull("The value should not be null.", value);
- assertEquals("The value is not correct.", '"' + date.toString() + '"', value);
+ assertEquals("The value is not correct.", '"' + FORMATTER.format(date) + '"', value);
}
@Test
@@ -192,7 +197,7 @@ public void testSerializationWithTypeInfo03() throws Exception
assertNotNull("The value should not be null.", value);
assertEquals("The value is not correct.",
- "[\"" + Instant.class.getName() + "\",\"" + date.toString() + "\"]", value);
+ "[\"" + Instant.class.getName() + "\",\"" + FORMATTER.format(date) + "\"]", value);
}
@Test
@@ -224,7 +229,7 @@ public void testDeserializationAsFloat03() throws Exception
Instant value = this.mapper.readValue(
DecimalUtils.toDecimal(date.getEpochSecond(), date.getNano()), Instant.class
- );
+ );
assertNotNull("The value should not be null.", value);
assertEquals("The value is not correct.", date, value);
@@ -309,7 +314,7 @@ public void testDeserializationAsString01() throws Exception
{
Instant date = Instant.ofEpochSecond(0L);
- Instant value = this.mapper.readValue('"' + date.toString() + '"', Instant.class);
+ Instant value = this.mapper.readValue('"' + FORMATTER.format(date) + '"', Instant.class);
assertNotNull("The value should not be null.", value);
assertEquals("The value is not correct.", date, value);
@@ -320,7 +325,7 @@ public void testDeserializationAsString02() throws Exception
{
Instant date = Instant.ofEpochSecond(123456789L, 183917322);
- Instant value = this.mapper.readValue('"' + date.toString() + '"', Instant.class);
+ Instant value = this.mapper.readValue('"' + FORMATTER.format(date) + '"', Instant.class);
assertNotNull("The value should not be null.", value);
assertEquals("The value is not correct.", date, value);
@@ -331,7 +336,7 @@ public void testDeserializationAsString03() throws Exception
{
Instant date = Instant.now();
- Instant value = this.mapper.readValue('"' + date.toString() + '"', Instant.class);
+ Instant value = this.mapper.readValue('"' + FORMATTER.format(date) + '"', Instant.class);
assertNotNull("The value should not be null.", value);
assertEquals("The value is not correct.", date, value);
@@ -345,7 +350,7 @@ public void testDeserializationWithTypeInfo01() throws Exception
this.mapper.addMixIn(Temporal.class, MockObjectConfiguration.class);
Temporal value = this.mapper.readValue(
"[\"" + Instant.class.getName() + "\",123456789.183917322]", Temporal.class
- );
+ );
assertNotNull("The value should not be null.", value);
assertTrue("The value should be an Instant.", value instanceof Instant);
@@ -361,7 +366,7 @@ public void testDeserializationWithTypeInfo02() throws Exception
this.mapper.addMixIn(Temporal.class, MockObjectConfiguration.class);
Temporal value = this.mapper.readValue(
"[\"" + Instant.class.getName() + "\",123456789]", Temporal.class
- );
+ );
assertNotNull("The value should not be null.", value);
assertTrue("The value should be an Instant.", value instanceof Instant);
@@ -377,7 +382,7 @@ public void testDeserializationWithTypeInfo03() throws Exception
this.mapper.addMixIn(Temporal.class, MockObjectConfiguration.class);
Temporal value = this.mapper.readValue(
"[\"" + Instant.class.getName() + "\",123456789422]", Temporal.class
- );
+ );
assertNotNull("The value should not be null.", value);
assertTrue("The value should be an Instant.", value instanceof Instant);
@@ -391,8 +396,8 @@ public void testDeserializationWithTypeInfo04() throws Exception
this.mapper.addMixIn(Temporal.class, MockObjectConfiguration.class);
Temporal value = this.mapper.readValue(
- "[\"" + Instant.class.getName() + "\",\"" + date.toString() + "\"]", Temporal.class
- );
+ "[\"" + Instant.class.getName() + "\",\"" + FORMATTER.format(date) + "\"]", Temporal.class
+ );
assertNotNull("The value should not be null.", value);
assertTrue("The value should be an Instant.", value instanceof Instant);
diff --git a/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestLocalDateKeySerialization.java b/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestLocalDateKeySerialization.java
index d2628df1..3a3cde4c 100644
--- a/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestLocalDateKeySerialization.java
+++ b/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestLocalDateKeySerialization.java
@@ -24,7 +24,7 @@ public class TestLocalDateKeySerialization {
@Before
public void setUp() {
this.om = new ObjectMapper();
- om.registerModule(new JSR310Module());
+ om.registerModule(new JavaTimeModule());
map = new HashMap<>();
}
diff --git a/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestLocalDateSerialization.java b/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestLocalDateSerialization.java
index 31ba52d9..ef49b4a6 100644
--- a/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestLocalDateSerialization.java
+++ b/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestLocalDateSerialization.java
@@ -16,16 +16,18 @@
package com.fasterxml.jackson.datatype.jsr310;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.SerializationFeature;
-import org.junit.Before;
-import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
import java.time.LocalDate;
import java.time.Month;
import java.time.temporal.Temporal;
-import static org.junit.Assert.*;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.SerializationFeature;
+import org.junit.Before;
+import org.junit.Test;
public class TestLocalDateSerialization
{
@@ -35,7 +37,7 @@ public class TestLocalDateSerialization
public void setUp()
{
this.mapper = new ObjectMapper();
- this.mapper.registerModule(new JSR310Module());
+ this.mapper.registerModule(new JavaTimeModule());
}
@Test
@@ -152,7 +154,7 @@ public void testDeserializationWithTypeInfo01() throws Exception
this.mapper.addMixIn(Temporal.class, MockObjectConfiguration.class);
Temporal value = this.mapper.readValue(
"[\"" + LocalDate.class.getName() + "\",\"" + date.toString() + "\"]", Temporal.class
- );
+ );
assertNotNull("The value should not be null.", value);
assertTrue("The value should be a LocalDate.", value instanceof LocalDate);
diff --git a/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestLocalDateTimeKeySerialization.java b/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestLocalDateTimeKeySerialization.java
index 9f5f7bcb..fe8efb21 100644
--- a/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestLocalDateTimeKeySerialization.java
+++ b/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestLocalDateTimeKeySerialization.java
@@ -30,7 +30,7 @@ public class TestLocalDateTimeKeySerialization {
@Before
public void setUp() {
this.om = new ObjectMapper();
- om.registerModule(new JSR310Module());
+ om.registerModule(new JavaTimeModule());
map = new HashMap<>();
}
diff --git a/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestLocalTimeKeySerialization.java b/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestLocalTimeKeySerialization.java
index c7320eaa..1a326d12 100644
--- a/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestLocalTimeKeySerialization.java
+++ b/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestLocalTimeKeySerialization.java
@@ -28,7 +28,7 @@ public class TestLocalTimeKeySerialization {
@Before
public void setUp() {
this.om = new ObjectMapper();
- om.registerModule(new JSR310Module());
+ om.registerModule(new JavaTimeModule());
map = new HashMap<>();
}
diff --git a/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestLocalTimeSerialization.java b/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestLocalTimeSerialization.java
index 95ed266b..9934c551 100644
--- a/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestLocalTimeSerialization.java
+++ b/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestLocalTimeSerialization.java
@@ -16,6 +16,13 @@
package com.fasterxml.jackson.datatype.jsr310;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.time.LocalTime;
+import java.time.temporal.Temporal;
+
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
@@ -23,11 +30,6 @@
import org.junit.Before;
import org.junit.Test;
-import java.time.LocalTime;
-import java.time.temporal.Temporal;
-
-import static org.junit.Assert.*;
-
public class TestLocalTimeSerialization
{
private ObjectMapper mapper;
@@ -36,7 +38,7 @@ public class TestLocalTimeSerialization
public void setUp()
{
this.mapper = new ObjectMapper();
- this.mapper.registerModule(new JSR310Module());
+ this.mapper.registerModule(new JavaTimeModule());
}
@After
@@ -323,7 +325,7 @@ public void testDeserializationWithTypeInfo01() throws Exception
this.mapper.addMixIn(Temporal.class, MockObjectConfiguration.class);
Temporal value = this.mapper.readValue(
"[\"" + LocalTime.class.getName() + "\",[22,31,5,829837]]", Temporal.class
- );
+ );
assertNotNull("The value should not be null.", value);
assertTrue("The value should be a LocalTime.", value instanceof LocalTime);
@@ -339,7 +341,7 @@ public void testDeserializationWithTypeInfo02() throws Exception
this.mapper.addMixIn(Temporal.class, MockObjectConfiguration.class);
Temporal value = this.mapper.readValue(
"[\"" + LocalTime.class.getName() + "\",[22,31,5,422]]", Temporal.class
- );
+ );
assertNotNull("The value should not be null.", value);
assertTrue("The value should be a LocalTime.", value instanceof LocalTime);
@@ -354,7 +356,7 @@ public void testDeserializationWithTypeInfo03() throws Exception
this.mapper.addMixIn(Temporal.class, MockObjectConfiguration.class);
Temporal value = this.mapper.readValue(
"[\"" + LocalTime.class.getName() + "\",\"" + time.toString() + "\"]", Temporal.class
- );
+ );
assertNotNull("The value should not be null.", value);
assertTrue("The value should be a LocalTime.", value instanceof LocalTime);
diff --git a/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestMonthDayKeySerialization.java b/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestMonthDayKeySerialization.java
index 80d407de..f47e1a80 100644
--- a/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestMonthDayKeySerialization.java
+++ b/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestMonthDayKeySerialization.java
@@ -23,7 +23,7 @@ public class TestMonthDayKeySerialization {
@Before
public void setUp() {
this.om = new ObjectMapper();
- om.registerModule(new JSR310Module());
+ om.registerModule(new JavaTimeModule());
map = new HashMap<>();
}
diff --git a/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestMonthDaySerialization.java b/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestMonthDaySerialization.java
index a548ec8e..9fd8928a 100644
--- a/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestMonthDaySerialization.java
+++ b/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestMonthDaySerialization.java
@@ -16,16 +16,18 @@
package com.fasterxml.jackson.datatype.jsr310;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
import java.time.Month;
import java.time.MonthDay;
import java.time.temporal.TemporalAccessor;
-import static org.junit.Assert.*;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
public class TestMonthDaySerialization
{
@@ -35,7 +37,7 @@ public class TestMonthDaySerialization
public void setUp()
{
this.mapper = new ObjectMapper();
- this.mapper.registerModule(new JSR310Module());
+ this.mapper.registerModule(new JavaTimeModule());
}
@After
diff --git a/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestNullKeySerialization.java b/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestNullKeySerialization.java
index 84130de9..76277b02 100644
--- a/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestNullKeySerialization.java
+++ b/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestNullKeySerialization.java
@@ -22,7 +22,7 @@ public class TestNullKeySerialization {
@Before
public void setUp() {
this.om = new ObjectMapper();
- om.registerModule(new JSR310Module());
+ om.registerModule(new JavaTimeModule());
map = new HashMap<>();
}
diff --git a/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestOffsetDateTimeKeySerialization.java b/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestOffsetDateTimeKeySerialization.java
index f9018062..cc166002 100644
--- a/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestOffsetDateTimeKeySerialization.java
+++ b/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestOffsetDateTimeKeySerialization.java
@@ -29,7 +29,7 @@ public class TestOffsetDateTimeKeySerialization {
@Before
public void setUp() {
this.om = new ObjectMapper();
- om.registerModule(new JSR310Module());
+ om.registerModule(new JavaTimeModule());
map = new HashMap<>();
}
diff --git a/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestOffsetDateTimeSerialization.java b/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestOffsetDateTimeSerialization.java
index ef48800d..419013fa 100644
--- a/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestOffsetDateTimeSerialization.java
+++ b/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestOffsetDateTimeSerialization.java
@@ -16,26 +16,31 @@
package com.fasterxml.jackson.datatype.jsr310;
-import com.fasterxml.jackson.databind.DeserializationFeature;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.SerializationFeature;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
import java.time.Instant;
import java.time.OffsetDateTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
+import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoField;
import java.time.temporal.ChronoUnit;
import java.time.temporal.Temporal;
import java.util.TimeZone;
-import static org.junit.Assert.*;
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.SerializationFeature;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
public class TestOffsetDateTimeSerialization
{
+ private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ISO_OFFSET_DATE_TIME;
+
private static final ZoneId Z1 = ZoneId.of("America/Chicago");
private static final ZoneId Z2 = ZoneId.of("America/Anchorage");
@@ -48,7 +53,7 @@ public class TestOffsetDateTimeSerialization
public void setUp()
{
this.mapper = new ObjectMapper();
- this.mapper.registerModule(new JSR310Module());
+ this.mapper.registerModule(new JavaTimeModule());
}
@After
@@ -144,7 +149,7 @@ public void testSerializationAsString01() throws Exception
String value = this.mapper.writeValueAsString(date);
assertNotNull("The value should not be null.", value);
- assertEquals("The value is not correct.", '"' + date.toString() + '"', value);
+ assertEquals("The value is not correct.", '"' + FORMATTER.format(date) + '"', value);
}
@Test
@@ -156,7 +161,7 @@ public void testSerializationAsString02() throws Exception
String value = this.mapper.writeValueAsString(date);
assertNotNull("The value should not be null.", value);
- assertEquals("The value is not correct.", '"' + date.toString() + '"', value);
+ assertEquals("The value is not correct.", '"' + FORMATTER.format(date) + '"', value);
}
@Test
@@ -168,7 +173,7 @@ public void testSerializationAsString03() throws Exception
String value = this.mapper.writeValueAsString(date);
assertNotNull("The value should not be null.", value);
- assertEquals("The value is not correct.", '"' + date.toString() + '"', value);
+ assertEquals("The value is not correct.", '"' + FORMATTER.format(date) + '"', value);
}
@Test
@@ -212,7 +217,7 @@ public void testSerializationWithTypeInfo03() throws Exception
assertNotNull("The value should not be null.", value);
assertEquals("The value is not correct.",
- "[\"" + OffsetDateTime.class.getName() + "\",\"" + date.toString() + "\"]", value);
+ "[\"" + OffsetDateTime.class.getName() + "\",\"" + FORMATTER.format(date) + "\"]", value);
}
@Test
@@ -272,7 +277,7 @@ public void testDeserializationAsFloat03WithoutTimeZone() throws Exception
OffsetDateTime value = this.mapper.readValue(
DecimalUtils.toDecimal(date.toEpochSecond(), date.getNano()), OffsetDateTime.class
- );
+ );
assertNotNull("The value should not be null.", value);
assertIsEqual(date, value);
@@ -287,7 +292,7 @@ public void testDeserializationAsFloat03WithTimeZone() throws Exception
this.mapper.setTimeZone(TimeZone.getDefault());
OffsetDateTime value = this.mapper.readValue(
DecimalUtils.toDecimal(date.toEpochSecond(), date.getNano()), OffsetDateTime.class
- );
+ );
assertNotNull("The value should not be null.", value);
assertIsEqual(date, value);
@@ -468,7 +473,7 @@ public void testDeserializationAsString01WithoutTimeZone() throws Exception
OffsetDateTime date = OffsetDateTime.ofInstant(Instant.ofEpochSecond(0L), Z1);
this.mapper.configure(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE, true);
- OffsetDateTime value = this.mapper.readValue('"' + date.toString() + '"', OffsetDateTime.class);
+ OffsetDateTime value = this.mapper.readValue('"' + FORMATTER.format(date) + '"', OffsetDateTime.class);
assertNotNull("The value should not be null.", value);
assertIsEqual(date, value);
@@ -482,7 +487,7 @@ public void testDeserializationAsString01WithTimeZone() throws Exception
this.mapper.configure(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE, true);
this.mapper.setTimeZone(TimeZone.getDefault());
- OffsetDateTime value = this.mapper.readValue('"' + date.toString() + '"', OffsetDateTime.class);
+ OffsetDateTime value = this.mapper.readValue('"' + FORMATTER.format(date) + '"', OffsetDateTime.class);
assertNotNull("The value should not be null.", value);
assertIsEqual(date, value);
@@ -496,7 +501,7 @@ public void testDeserializationAsString01WithTimeZoneTurnedOff() throws Exceptio
this.mapper.configure(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE, false);
this.mapper.setTimeZone(TimeZone.getDefault());
- OffsetDateTime value = this.mapper.readValue('"' + date.toString() + '"', OffsetDateTime.class);
+ OffsetDateTime value = this.mapper.readValue('"' + FORMATTER.format(date) + '"', OffsetDateTime.class);
assertNotNull("The value should not be null.", value);
assertIsEqual(date, value);
@@ -509,7 +514,7 @@ public void testDeserializationAsString02WithoutTimeZone() throws Exception
OffsetDateTime date = OffsetDateTime.ofInstant(Instant.ofEpochSecond(123456789L, 183917322), Z2);
this.mapper.configure(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE, true);
- OffsetDateTime value = this.mapper.readValue('"' + date.toString() + '"', OffsetDateTime.class);
+ OffsetDateTime value = this.mapper.readValue('"' + FORMATTER.format(date) + '"', OffsetDateTime.class);
assertNotNull("The value should not be null.", value);
assertIsEqual(date, value);
@@ -523,7 +528,7 @@ public void testDeserializationAsString02WithTimeZone() throws Exception
this.mapper.configure(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE, true);
this.mapper.setTimeZone(TimeZone.getDefault());
- OffsetDateTime value = this.mapper.readValue('"' + date.toString() + '"', OffsetDateTime.class);
+ OffsetDateTime value = this.mapper.readValue('"' + FORMATTER.format(date) + '"', OffsetDateTime.class);
assertNotNull("The value should not be null.", value);
assertIsEqual(date, value);
@@ -537,7 +542,7 @@ public void testDeserializationAsString02WithTimeZoneTurnedOff() throws Exceptio
this.mapper.configure(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE, false);
this.mapper.setTimeZone(TimeZone.getDefault());
- OffsetDateTime value = this.mapper.readValue('"' + date.toString() + '"', OffsetDateTime.class);
+ OffsetDateTime value = this.mapper.readValue('"' + FORMATTER.format(date) + '"', OffsetDateTime.class);
assertNotNull("The value should not be null.", value);
assertIsEqual(date, value);
@@ -550,7 +555,7 @@ public void testDeserializationAsString03WithoutTimeZone() throws Exception
OffsetDateTime date = OffsetDateTime.now(Z3);
this.mapper.configure(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE, true);
- OffsetDateTime value = this.mapper.readValue('"' + date.toString() + '"', OffsetDateTime.class);
+ OffsetDateTime value = this.mapper.readValue('"' + FORMATTER.format(date) + '"', OffsetDateTime.class);
assertNotNull("The value should not be null.", value);
assertIsEqual(date, value);
@@ -564,7 +569,7 @@ public void testDeserializationAsString03WithTimeZone() throws Exception
this.mapper.configure(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE, true);
this.mapper.setTimeZone(TimeZone.getDefault());
- OffsetDateTime value = this.mapper.readValue('"' + date.toString() + '"', OffsetDateTime.class);
+ OffsetDateTime value = this.mapper.readValue('"' + FORMATTER.format(date) + '"', OffsetDateTime.class);
assertNotNull("The value should not be null.", value);
assertIsEqual(date, value);
@@ -578,7 +583,7 @@ public void testDeserializationAsString03WithTimeZoneTurnedOff() throws Exceptio
this.mapper.configure(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE, false);
this.mapper.setTimeZone(TimeZone.getDefault());
- OffsetDateTime value = this.mapper.readValue('"' + date.toString() + '"', OffsetDateTime.class);
+ OffsetDateTime value = this.mapper.readValue('"' + FORMATTER.format(date) + '"', OffsetDateTime.class);
assertNotNull("The value should not be null.", value);
assertIsEqual(date, value);
@@ -593,7 +598,7 @@ public void testDeserializationWithTypeInfo01WithoutTimeZone() throws Exception
this.mapper.addMixIn(Temporal.class, MockObjectConfiguration.class);
Temporal value = this.mapper.readValue(
"[\"" + OffsetDateTime.class.getName() + "\",123456789.183917322]", Temporal.class
- );
+ );
assertNotNull("The value should not be null.", value);
assertTrue("The value should be an OffsetDateTime.", value instanceof OffsetDateTime);
@@ -610,7 +615,7 @@ public void testDeserializationWithTypeInfo01WithTimeZone() throws Exception
this.mapper.addMixIn(Temporal.class, MockObjectConfiguration.class);
Temporal value = this.mapper.readValue(
"[\"" + OffsetDateTime.class.getName() + "\",123456789.183917322]", Temporal.class
- );
+ );
assertNotNull("The value should not be null.", value);
assertTrue("The value should be an OffsetDateTime.", value instanceof OffsetDateTime);
@@ -627,7 +632,7 @@ public void testDeserializationWithTypeInfo02WithoutTimeZone() throws Exception
this.mapper.addMixIn(Temporal.class, MockObjectConfiguration.class);
Temporal value = this.mapper.readValue(
"[\"" + OffsetDateTime.class.getName() + "\",123456789]", Temporal.class
- );
+ );
assertNotNull("The value should not be null.", value);
assertTrue("The value should be an OffsetDateTime.", value instanceof OffsetDateTime);
@@ -645,7 +650,7 @@ public void testDeserializationWithTypeInfo02WithTimeZone() throws Exception
this.mapper.addMixIn(Temporal.class, MockObjectConfiguration.class);
Temporal value = this.mapper.readValue(
"[\"" + OffsetDateTime.class.getName() + "\",123456789]", Temporal.class
- );
+ );
assertNotNull("The value should not be null.", value);
assertTrue("The value should be an OffsetDateTime.", value instanceof OffsetDateTime);
@@ -662,7 +667,7 @@ public void testDeserializationWithTypeInfo03WithoutTimeZone() throws Exception
this.mapper.addMixIn(Temporal.class, MockObjectConfiguration.class);
Temporal value = this.mapper.readValue(
"[\"" + OffsetDateTime.class.getName() + "\",123456789422]", Temporal.class
- );
+ );
assertNotNull("The value should not be null.", value);
assertTrue("The value should be an OffsetDateTime.", value instanceof OffsetDateTime);
@@ -680,7 +685,7 @@ public void testDeserializationWithTypeInfo03WithTimeZone() throws Exception
this.mapper.addMixIn(Temporal.class, MockObjectConfiguration.class);
Temporal value = this.mapper.readValue(
"[\"" + OffsetDateTime.class.getName() + "\",123456789422]", Temporal.class
- );
+ );
assertNotNull("The value should not be null.", value);
assertTrue("The value should be an OffsetDateTime.", value instanceof OffsetDateTime);
@@ -696,8 +701,8 @@ public void testDeserializationWithTypeInfo04WithoutTimeZone() throws Exception
this.mapper.configure(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE, true);
this.mapper.addMixIn(Temporal.class, MockObjectConfiguration.class);
Temporal value = this.mapper.readValue(
- "[\"" + OffsetDateTime.class.getName() + "\",\"" + date.toString() + "\"]", Temporal.class
- );
+ "[\"" + OffsetDateTime.class.getName() + "\",\"" + FORMATTER.format(date) + "\"]", Temporal.class
+ );
assertNotNull("The value should not be null.", value);
assertTrue("The value should be an OffsetDateTime.", value instanceof OffsetDateTime);
@@ -714,8 +719,8 @@ public void testDeserializationWithTypeInfo04WithTimeZone() throws Exception
this.mapper.setTimeZone(TimeZone.getDefault());
this.mapper.addMixIn(Temporal.class, MockObjectConfiguration.class);
Temporal value = this.mapper.readValue(
- "[\"" + OffsetDateTime.class.getName() + "\",\"" + date.toString() + "\"]", Temporal.class
- );
+ "[\"" + OffsetDateTime.class.getName() + "\",\"" + FORMATTER.format(date) + "\"]", Temporal.class
+ );
assertNotNull("The value should not be null.", value);
assertTrue("The value should be an OffsetDateTime.", value instanceof OffsetDateTime);
@@ -732,12 +737,12 @@ public void testDeserializationWithTypeInfo04WithTimeZoneTurnedOff() throws Exce
this.mapper.setTimeZone(TimeZone.getDefault());
this.mapper.addMixIn(Temporal.class, MockObjectConfiguration.class);
Temporal value = this.mapper.readValue(
- "[\"" + OffsetDateTime.class.getName() + "\",\"" + date.toString() + "\"]", Temporal.class
- );
+ "[\"" + OffsetDateTime.class.getName() + "\",\"" + FORMATTER.format(date) + "\"]", Temporal.class
+ );
assertNotNull("The value should not be null.", value);
assertTrue("The value should be an OffsetDateTime.", value instanceof OffsetDateTime);
- OffsetDateTime cast = (OffsetDateTime)value;
+ OffsetDateTime cast = (OffsetDateTime) value;
assertIsEqual(date, cast);
assertEquals("The time zone is not correct.", getOffset(cast, Z3), cast.getOffset());
}
diff --git a/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestOffsetTimeKeySerialization.java b/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestOffsetTimeKeySerialization.java
index ab619696..8e7b13bd 100644
--- a/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestOffsetTimeKeySerialization.java
+++ b/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestOffsetTimeKeySerialization.java
@@ -28,7 +28,7 @@ public class TestOffsetTimeKeySerialization {
@Before
public void setUp() {
this.om = new ObjectMapper();
- om.registerModule(new JSR310Module());
+ om.registerModule(new JavaTimeModule());
map = new HashMap<>();
}
diff --git a/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestOffsetTimeSerialization.java b/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestOffsetTimeSerialization.java
index 179101fd..95c97ccd 100644
--- a/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestOffsetTimeSerialization.java
+++ b/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestOffsetTimeSerialization.java
@@ -16,6 +16,14 @@
package com.fasterxml.jackson.datatype.jsr310;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.time.OffsetTime;
+import java.time.ZoneOffset;
+import java.time.temporal.Temporal;
+
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
@@ -23,12 +31,6 @@
import org.junit.Before;
import org.junit.Test;
-import java.time.OffsetTime;
-import java.time.ZoneOffset;
-import java.time.temporal.Temporal;
-
-import static org.junit.Assert.*;
-
public class TestOffsetTimeSerialization
{
private ObjectMapper mapper;
@@ -37,7 +39,7 @@ public class TestOffsetTimeSerialization
public void setUp()
{
this.mapper = new ObjectMapper();
- this.mapper.registerModule(new JSR310Module());
+ this.mapper.registerModule(new JavaTimeModule());
}
@After
@@ -326,7 +328,7 @@ public void testDeserializationWithTypeInfo01() throws Exception
this.mapper.addMixIn(Temporal.class, MockObjectConfiguration.class);
Temporal value = this.mapper.readValue(
"[\"" + OffsetTime.class.getName() + "\",[22,31,5,829837,\"+11:00\"]]", Temporal.class
- );
+ );
assertNotNull("The value should not be null.", value);
assertTrue("The value should be a OffsetTime.", value instanceof OffsetTime);
@@ -342,7 +344,7 @@ public void testDeserializationWithTypeInfo02() throws Exception
this.mapper.addMixIn(Temporal.class, MockObjectConfiguration.class);
Temporal value = this.mapper.readValue(
"[\"" + OffsetTime.class.getName() + "\",[22,31,5,422,\"+11:00\"]]", Temporal.class
- );
+ );
assertNotNull("The value should not be null.", value);
assertTrue("The value should be a OffsetTime.", value instanceof OffsetTime);
@@ -357,7 +359,7 @@ public void testDeserializationWithTypeInfo03() throws Exception
this.mapper.addMixIn(Temporal.class, MockObjectConfiguration.class);
Temporal value = this.mapper.readValue(
"[\"" + OffsetTime.class.getName() + "\",\"" + time.toString() + "\"]", Temporal.class
- );
+ );
assertNotNull("The value should not be null.", value);
assertTrue("The value should be a OffsetTime.", value instanceof OffsetTime);
diff --git a/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestPeriodKeySerialization.java b/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestPeriodKeySerialization.java
index d0d6095a..197d5519 100644
--- a/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestPeriodKeySerialization.java
+++ b/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestPeriodKeySerialization.java
@@ -25,7 +25,7 @@ public class TestPeriodKeySerialization {
@Before
public void setUp() {
this.om = new ObjectMapper();
- om.registerModule(new JSR310Module());
+ om.registerModule(new JavaTimeModule());
map = new HashMap<>();
}
diff --git a/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestPeriodSerialization.java b/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestPeriodSerialization.java
index 91074df5..82d476d1 100644
--- a/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestPeriodSerialization.java
+++ b/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestPeriodSerialization.java
@@ -16,15 +16,17 @@
package com.fasterxml.jackson.datatype.jsr310;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
import java.time.Period;
import java.time.temporal.TemporalAmount;
-import static org.junit.Assert.*;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
public class TestPeriodSerialization
{
@@ -34,7 +36,7 @@ public class TestPeriodSerialization
public void setUp()
{
this.mapper = new ObjectMapper();
- this.mapper.registerModule(new JSR310Module());
+ this.mapper.registerModule(new JavaTimeModule());
}
@After
@@ -108,7 +110,7 @@ public void testDeserializationWithTypeInfo01() throws Exception
this.mapper.addMixIn(TemporalAmount.class, MockObjectConfiguration.class);
TemporalAmount value = this.mapper.readValue(
"[\"" + Period.class.getName() + "\",\"" + period.toString() + "\"]", TemporalAmount.class
- );
+ );
assertNotNull("The value should not be null.", value);
assertTrue("The value should be a Period.", value instanceof Period);
diff --git a/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestYearKeySerialization.java b/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestYearKeySerialization.java
index 997a1003..44597f25 100644
--- a/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestYearKeySerialization.java
+++ b/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestYearKeySerialization.java
@@ -20,7 +20,7 @@ public class TestYearKeySerialization {
@Before
public void setUp() {
this.om = new ObjectMapper();
- om.registerModule(new JSR310Module());
+ om.registerModule(new JavaTimeModule());
map = new HashMap<>();
}
diff --git a/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestYearMonthKeySerialization.java b/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestYearMonthKeySerialization.java
index 949691f4..69b6be14 100644
--- a/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestYearMonthKeySerialization.java
+++ b/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestYearMonthKeySerialization.java
@@ -21,7 +21,7 @@ public class TestYearMonthKeySerialization {
@Before
public void setUp() {
this.om = new ObjectMapper();
- om.registerModule(new JSR310Module());
+ om.registerModule(new JavaTimeModule());
map = new HashMap<>();
}
diff --git a/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestYearMonthSerialization.java b/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestYearMonthSerialization.java
index ebc1f3bd..977ebf3e 100644
--- a/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestYearMonthSerialization.java
+++ b/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestYearMonthSerialization.java
@@ -16,22 +16,23 @@
package com.fasterxml.jackson.datatype.jsr310;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.SerializationFeature;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.time.Month;
+import java.time.YearMonth;
+import java.time.temporal.Temporal;
+
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
-
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.SerializationFeature;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
-import java.time.Month;
-import java.time.YearMonth;
-import java.time.temporal.Temporal;
-
-import static org.junit.Assert.*;
-
public class TestYearMonthSerialization
{
private ObjectMapper mapper;
@@ -40,7 +41,7 @@ public class TestYearMonthSerialization
public void setUp()
{
this.mapper = new ObjectMapper();
- this.mapper.registerModule(new JSR310Module());
+ this.mapper.registerModule(new JavaTimeModule());
}
@After
@@ -171,21 +172,20 @@ public void testDeserializationWithTypeInfo01() throws Exception
assertTrue("The value should be a YearMonth.", value instanceof YearMonth);
assertEquals("The value is not correct.", yearMonth, value);
}
-
-
- private static class SimpleAggregate
+
+ private static class SimpleAggregate
{
@JsonProperty("yearMonth")
- @JsonFormat(pattern="yyMM")
+ @JsonFormat(pattern = "yyMM")
final YearMonth yearMonth;
-
+
@JsonCreator
SimpleAggregate(@JsonProperty("yearMonth") YearMonth yearMonth)
{
this.yearMonth = yearMonth;
}
}
-
+
@Test
public void testSerializationWithPattern01() throws Exception
{
diff --git a/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestYearSerialization.java b/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestYearSerialization.java
index 70d149ce..1be2992a 100644
--- a/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestYearSerialization.java
+++ b/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestYearSerialization.java
@@ -16,15 +16,17 @@
package com.fasterxml.jackson.datatype.jsr310;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
import java.time.Year;
import java.time.temporal.Temporal;
-import static org.junit.Assert.*;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
public class TestYearSerialization
{
@@ -34,7 +36,7 @@ public class TestYearSerialization
public void setUp()
{
this.mapper = new ObjectMapper();
- this.mapper.registerModule(new JSR310Module());
+ this.mapper.registerModule(new JavaTimeModule());
}
@After
diff --git a/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestZoneIdKeySerialization.java b/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestZoneIdKeySerialization.java
index aa28c2e8..b2280f2c 100644
--- a/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestZoneIdKeySerialization.java
+++ b/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestZoneIdKeySerialization.java
@@ -27,7 +27,7 @@ public class TestZoneIdKeySerialization {
@Before
public void setUp() {
this.om = new ObjectMapper();
- om.registerModule(new JSR310Module());
+ om.registerModule(new JavaTimeModule());
map = new HashMap<>();
}
diff --git a/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestZoneIdSerialization.java b/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestZoneIdSerialization.java
index 1cf3fda7..5619c740 100644
--- a/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestZoneIdSerialization.java
+++ b/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestZoneIdSerialization.java
@@ -16,15 +16,16 @@
package com.fasterxml.jackson.datatype.jsr310;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.time.ZoneId;
+
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
-import java.time.ZoneId;
-
-import static org.junit.Assert.*;
-
public class TestZoneIdSerialization
{
private ObjectMapper mapper;
@@ -33,7 +34,7 @@ public class TestZoneIdSerialization
public void setUp()
{
this.mapper = new ObjectMapper();
- this.mapper.registerModule(new JSR310Module());
+ this.mapper.registerModule(new JavaTimeModule());
}
@After
diff --git a/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestZoneOffsetKeySerialization.java b/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestZoneOffsetKeySerialization.java
index cff25bf0..7a00e15d 100644
--- a/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestZoneOffsetKeySerialization.java
+++ b/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestZoneOffsetKeySerialization.java
@@ -25,7 +25,7 @@ public class TestZoneOffsetKeySerialization {
@Before
public void setUp() {
this.om = new ObjectMapper();
- om.registerModule(new JSR310Module());
+ om.registerModule(new JavaTimeModule());
map = new HashMap<>();
}
diff --git a/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestZoneOffsetSerialization.java b/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestZoneOffsetSerialization.java
index 08f9de89..5207dc45 100644
--- a/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestZoneOffsetSerialization.java
+++ b/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestZoneOffsetSerialization.java
@@ -16,15 +16,17 @@
package com.fasterxml.jackson.datatype.jsr310;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
import java.time.ZoneId;
import java.time.ZoneOffset;
-import static org.junit.Assert.*;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
public class TestZoneOffsetSerialization
{
@@ -34,7 +36,7 @@ public class TestZoneOffsetSerialization
public void setUp()
{
this.mapper = new ObjectMapper();
- this.mapper.registerModule(new JSR310Module());
+ this.mapper.registerModule(new JavaTimeModule());
}
@After
diff --git a/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestZonedDateTimeKeySerialization.java b/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestZonedDateTimeKeySerialization.java
index 02565d2d..520a106f 100644
--- a/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestZonedDateTimeKeySerialization.java
+++ b/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestZonedDateTimeKeySerialization.java
@@ -39,7 +39,7 @@ public class TestZonedDateTimeKeySerialization {
@Before
public void setUp() {
this.om = new ObjectMapper();
- om.registerModule(new JSR310Module());
+ om.registerModule(new JavaTimeModule());
map = new HashMap<>();
}
diff --git a/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestZonedDateTimeSerialization.java b/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestZonedDateTimeSerialization.java
index 5a2ac147..a9ab9e75 100644
--- a/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestZonedDateTimeSerialization.java
+++ b/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestZonedDateTimeSerialization.java
@@ -16,25 +16,30 @@
package com.fasterxml.jackson.datatype.jsr310;
-import com.fasterxml.jackson.databind.DeserializationFeature;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.SerializationFeature;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
import java.time.Instant;
import java.time.ZoneId;
import java.time.ZonedDateTime;
+import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoField;
import java.time.temporal.ChronoUnit;
import java.time.temporal.Temporal;
import java.util.TimeZone;
-import static org.junit.Assert.*;
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.SerializationFeature;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
public class TestZonedDateTimeSerialization
{
+ private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ISO_OFFSET_DATE_TIME;
+
private static final ZoneId Z1 = ZoneId.of("America/Chicago");
private static final ZoneId Z2 = ZoneId.of("America/Anchorage");
@@ -43,13 +48,15 @@ public class TestZonedDateTimeSerialization
private static final ZoneId GMT = ZoneId.of("GMT");
+ private static final ZoneId FIX_OFFSET = ZoneId.of("-08:00");
+
private ObjectMapper mapper;
@Before
public void setUp()
{
this.mapper = new ObjectMapper();
- this.mapper.registerModule(new JSR310Module());
+ this.mapper.registerModule(new JavaTimeModule());
}
@After
@@ -145,7 +152,7 @@ public void testSerializationAsString01() throws Exception
String value = this.mapper.writeValueAsString(date);
assertNotNull("The value should not be null.", value);
- assertEquals("The value is not correct.", '"' + date.toString() + '"', value);
+ assertEquals("The value is not correct.", '"' + FORMATTER.format(date) + '"', value);
}
@Test
@@ -157,7 +164,7 @@ public void testSerializationAsString02() throws Exception
String value = this.mapper.writeValueAsString(date);
assertNotNull("The value should not be null.", value);
- assertEquals("The value is not correct.", '"' + date.toString() + '"', value);
+ assertEquals("The value is not correct.", '"' + FORMATTER.format(date) + '"', value);
}
@Test
@@ -169,7 +176,7 @@ public void testSerializationAsString03() throws Exception
String value = this.mapper.writeValueAsString(date);
assertNotNull("The value should not be null.", value);
- assertEquals("The value is not correct.", '"' + date.toString() + '"', value);
+ assertEquals("The value is not correct.", '"' + FORMATTER.format(date) + '"', value);
}
@Test
@@ -213,7 +220,7 @@ public void testSerializationWithTypeInfo03() throws Exception
assertNotNull("The value should not be null.", value);
assertEquals("The value is not correct.",
- "[\"" + ZonedDateTime.class.getName() + "\",\"" + date.toString() + "\"]", value);
+ "[\"" + ZonedDateTime.class.getName() + "\",\"" + FORMATTER.format(date) + "\"]", value);
}
@Test
@@ -273,7 +280,7 @@ public void testDeserializationAsFloat03WithoutTimeZone() throws Exception
ZonedDateTime value = this.mapper.readValue(
DecimalUtils.toDecimal(date.toEpochSecond(), date.getNano()), ZonedDateTime.class
- );
+ );
assertNotNull("The value should not be null.", value);
assertIsEqual(date, value);
@@ -288,7 +295,7 @@ public void testDeserializationAsFloat03WithTimeZone() throws Exception
this.mapper.setTimeZone(TimeZone.getDefault());
ZonedDateTime value = this.mapper.readValue(
DecimalUtils.toDecimal(date.toEpochSecond(), date.getNano()), ZonedDateTime.class
- );
+ );
assertNotNull("The value should not be null.", value);
assertIsEqual(date, value);
@@ -469,7 +476,7 @@ public void testDeserializationAsString01WithoutTimeZone() throws Exception
ZonedDateTime date = ZonedDateTime.ofInstant(Instant.ofEpochSecond(0L), Z1);
this.mapper.configure(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE, true);
- ZonedDateTime value = this.mapper.readValue('"' + date.toString() + '"', ZonedDateTime.class);
+ ZonedDateTime value = this.mapper.readValue('"' + FORMATTER.format(date) + '"', ZonedDateTime.class);
assertNotNull("The value should not be null.", value);
assertIsEqual(date, value);
@@ -483,7 +490,7 @@ public void testDeserializationAsString01WithTimeZone() throws Exception
this.mapper.configure(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE, true);
this.mapper.setTimeZone(TimeZone.getDefault());
- ZonedDateTime value = this.mapper.readValue('"' + date.toString() + '"', ZonedDateTime.class);
+ ZonedDateTime value = this.mapper.readValue('"' + FORMATTER.format(date) + '"', ZonedDateTime.class);
assertNotNull("The value should not be null.", value);
assertIsEqual(date, value);
@@ -493,15 +500,15 @@ public void testDeserializationAsString01WithTimeZone() throws Exception
@Test
public void testDeserializationAsString01WithTimeZoneTurnedOff() throws Exception
{
- ZonedDateTime date = ZonedDateTime.ofInstant(Instant.ofEpochSecond(0L), Z1);
+ ZonedDateTime date = ZonedDateTime.ofInstant(Instant.ofEpochSecond(0L), FIX_OFFSET);
this.mapper.configure(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE, false);
this.mapper.setTimeZone(TimeZone.getDefault());
- ZonedDateTime value = this.mapper.readValue('"' + date.toString() + '"', ZonedDateTime.class);
+ ZonedDateTime value = this.mapper.readValue('"' + FORMATTER.format(date) + '"', ZonedDateTime.class);
assertNotNull("The value should not be null.", value);
assertIsEqual(date, value);
- assertEquals("The time zone is not correct.", Z1, value.getZone());
+ assertEquals("The time zone is not correct.", FIX_OFFSET, value.getZone());
}
@Test
@@ -510,7 +517,7 @@ public void testDeserializationAsString02WithoutTimeZone() throws Exception
ZonedDateTime date = ZonedDateTime.ofInstant(Instant.ofEpochSecond(123456789L, 183917322), Z2);
this.mapper.configure(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE, true);
- ZonedDateTime value = this.mapper.readValue('"' + date.toString() + '"', ZonedDateTime.class);
+ ZonedDateTime value = this.mapper.readValue('"' + FORMATTER.format(date) + '"', ZonedDateTime.class);
assertNotNull("The value should not be null.", value);
assertIsEqual(date, value);
@@ -524,7 +531,7 @@ public void testDeserializationAsString02WithTimeZone() throws Exception
this.mapper.configure(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE, true);
this.mapper.setTimeZone(TimeZone.getDefault());
- ZonedDateTime value = this.mapper.readValue('"' + date.toString() + '"', ZonedDateTime.class);
+ ZonedDateTime value = this.mapper.readValue('"' + FORMATTER.format(date) + '"', ZonedDateTime.class);
assertNotNull("The value should not be null.", value);
assertIsEqual(date, value);
@@ -534,15 +541,15 @@ public void testDeserializationAsString02WithTimeZone() throws Exception
@Test
public void testDeserializationAsString02WithTimeZoneTurnedOff() throws Exception
{
- ZonedDateTime date = ZonedDateTime.ofInstant(Instant.ofEpochSecond(123456789L, 183917322), Z2);
+ ZonedDateTime date = ZonedDateTime.ofInstant(Instant.ofEpochSecond(123456789L, 183917322), FIX_OFFSET);
this.mapper.configure(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE, false);
this.mapper.setTimeZone(TimeZone.getDefault());
- ZonedDateTime value = this.mapper.readValue('"' + date.toString() + '"', ZonedDateTime.class);
+ ZonedDateTime value = this.mapper.readValue('"' + FORMATTER.format(date) + '"', ZonedDateTime.class);
assertNotNull("The value should not be null.", value);
assertIsEqual(date, value);
- assertEquals("The time zone is not correct.", Z2, value.getZone());
+ assertEquals("The time zone is not correct.", FIX_OFFSET, value.getZone());
}
@Test
@@ -551,7 +558,7 @@ public void testDeserializationAsString03WithoutTimeZone() throws Exception
ZonedDateTime date = ZonedDateTime.now(Z3);
this.mapper.configure(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE, true);
- ZonedDateTime value = this.mapper.readValue('"' + date.toString() + '"', ZonedDateTime.class);
+ ZonedDateTime value = this.mapper.readValue('"' + FORMATTER.format(date) + '"', ZonedDateTime.class);
assertNotNull("The value should not be null.", value);
assertIsEqual(date, value);
@@ -565,7 +572,7 @@ public void testDeserializationAsString03WithTimeZone() throws Exception
this.mapper.configure(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE, true);
this.mapper.setTimeZone(TimeZone.getDefault());
- ZonedDateTime value = this.mapper.readValue('"' + date.toString() + '"', ZonedDateTime.class);
+ ZonedDateTime value = this.mapper.readValue('"' + FORMATTER.format(date) + '"', ZonedDateTime.class);
assertNotNull("The value should not be null.", value);
assertIsEqual(date, value);
@@ -575,15 +582,15 @@ public void testDeserializationAsString03WithTimeZone() throws Exception
@Test
public void testDeserializationAsString03WithTimeZoneTurnedOff() throws Exception
{
- ZonedDateTime date = ZonedDateTime.now(Z3);
+ ZonedDateTime date = ZonedDateTime.now(FIX_OFFSET);
this.mapper.configure(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE, false);
this.mapper.setTimeZone(TimeZone.getDefault());
- ZonedDateTime value = this.mapper.readValue('"' + date.toString() + '"', ZonedDateTime.class);
+ ZonedDateTime value = this.mapper.readValue('"' + FORMATTER.format(date) + '"', ZonedDateTime.class);
assertNotNull("The value should not be null.", value);
assertIsEqual(date, value);
- assertEquals("The time zone is not correct.", Z3, value.getZone());
+ assertEquals("The time zone is not correct.", FIX_OFFSET, value.getZone());
}
@Test
@@ -594,7 +601,7 @@ public void testDeserializationWithTypeInfo01WithoutTimeZone() throws Exception
this.mapper.addMixIn(Temporal.class, MockObjectConfiguration.class);
Temporal value = this.mapper.readValue(
"[\"" + ZonedDateTime.class.getName() + "\",123456789.183917322]", Temporal.class
- );
+ );
assertNotNull("The value should not be null.", value);
assertTrue("The value should be an ZonedDateTime.", value instanceof ZonedDateTime);
@@ -611,7 +618,7 @@ public void testDeserializationWithTypeInfo01WithTimeZone() throws Exception
this.mapper.addMixIn(Temporal.class, MockObjectConfiguration.class);
Temporal value = this.mapper.readValue(
"[\"" + ZonedDateTime.class.getName() + "\",123456789.183917322]", Temporal.class
- );
+ );
assertNotNull("The value should not be null.", value);
assertTrue("The value should be an ZonedDateTime.", value instanceof ZonedDateTime);
@@ -628,7 +635,7 @@ public void testDeserializationWithTypeInfo02WithoutTimeZone() throws Exception
this.mapper.addMixIn(Temporal.class, MockObjectConfiguration.class);
Temporal value = this.mapper.readValue(
"[\"" + ZonedDateTime.class.getName() + "\",123456789]", Temporal.class
- );
+ );
assertNotNull("The value should not be null.", value);
assertTrue("The value should be an ZonedDateTime.", value instanceof ZonedDateTime);
@@ -646,7 +653,7 @@ public void testDeserializationWithTypeInfo02WithTimeZone() throws Exception
this.mapper.addMixIn(Temporal.class, MockObjectConfiguration.class);
Temporal value = this.mapper.readValue(
"[\"" + ZonedDateTime.class.getName() + "\",123456789]", Temporal.class
- );
+ );
assertNotNull("The value should not be null.", value);
assertTrue("The value should be an ZonedDateTime.", value instanceof ZonedDateTime);
@@ -663,7 +670,7 @@ public void testDeserializationWithTypeInfo03WithoutTimeZone() throws Exception
this.mapper.addMixIn(Temporal.class, MockObjectConfiguration.class);
Temporal value = this.mapper.readValue(
"[\"" + ZonedDateTime.class.getName() + "\",123456789422]", Temporal.class
- );
+ );
assertNotNull("The value should not be null.", value);
assertTrue("The value should be an ZonedDateTime.", value instanceof ZonedDateTime);
@@ -681,7 +688,7 @@ public void testDeserializationWithTypeInfo03WithTimeZone() throws Exception
this.mapper.addMixIn(Temporal.class, MockObjectConfiguration.class);
Temporal value = this.mapper.readValue(
"[\"" + ZonedDateTime.class.getName() + "\",123456789422]", Temporal.class
- );
+ );
assertNotNull("The value should not be null.", value);
assertTrue("The value should be an ZonedDateTime.", value instanceof ZonedDateTime);
@@ -697,8 +704,8 @@ public void testDeserializationWithTypeInfo04WithoutTimeZone() throws Exception
this.mapper.configure(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE, true);
this.mapper.addMixIn(Temporal.class, MockObjectConfiguration.class);
Temporal value = this.mapper.readValue(
- "[\"" + ZonedDateTime.class.getName() + "\",\"" + date.toString() + "\"]", Temporal.class
- );
+ "[\"" + ZonedDateTime.class.getName() + "\",\"" + FORMATTER.format(date) + "\"]", Temporal.class
+ );
assertNotNull("The value should not be null.", value);
assertTrue("The value should be an ZonedDateTime.", value instanceof ZonedDateTime);
@@ -715,8 +722,8 @@ public void testDeserializationWithTypeInfo04WithTimeZone() throws Exception
this.mapper.setTimeZone(TimeZone.getDefault());
this.mapper.addMixIn(Temporal.class, MockObjectConfiguration.class);
Temporal value = this.mapper.readValue(
- "[\"" + ZonedDateTime.class.getName() + "\",\"" + date.toString() + "\"]", Temporal.class
- );
+ "[\"" + ZonedDateTime.class.getName() + "\",\"" + FORMATTER.format(date) + "\"]", Temporal.class
+ );
assertNotNull("The value should not be null.", value);
assertTrue("The value should be an ZonedDateTime.", value instanceof ZonedDateTime);
@@ -727,19 +734,19 @@ public void testDeserializationWithTypeInfo04WithTimeZone() throws Exception
@Test
public void testDeserializationWithTypeInfo04WithTimeZoneTurnedOff() throws Exception
{
- ZonedDateTime date = ZonedDateTime.now(Z3);
+ ZonedDateTime date = ZonedDateTime.now(FIX_OFFSET);
this.mapper.configure(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE, false);
this.mapper.setTimeZone(TimeZone.getDefault());
this.mapper.addMixIn(Temporal.class, MockObjectConfiguration.class);
Temporal value = this.mapper.readValue(
- "[\"" + ZonedDateTime.class.getName() + "\",\"" + date.toString() + "\"]", Temporal.class
- );
+ "[\"" + ZonedDateTime.class.getName() + "\",\"" + FORMATTER.format(date) + "\"]", Temporal.class
+ );
assertNotNull("The value should not be null.", value);
assertTrue("The value should be an ZonedDateTime.", value instanceof ZonedDateTime);
assertIsEqual(date, (ZonedDateTime) value);
- assertEquals("The time zone is not correct.", Z3, ((ZonedDateTime) value).getZone());
+ assertEquals("The time zone is not correct.", FIX_OFFSET, ((ZonedDateTime) value).getZone());
}
private static void assertIsEqual(ZonedDateTime expected, ZonedDateTime actual)
diff --git a/src/test/java/com/fasterxml/jackson/datatype/jsr310/old/MockObjectConfiguration.java b/src/test/java/com/fasterxml/jackson/datatype/jsr310/old/MockObjectConfiguration.java
new file mode 100644
index 00000000..599bdc59
--- /dev/null
+++ b/src/test/java/com/fasterxml/jackson/datatype/jsr310/old/MockObjectConfiguration.java
@@ -0,0 +1,24 @@
+/*
+ * Copyright 2013 FasterXML.com
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may
+ * not use this file except in compliance with the License. You may obtain
+ * a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+
+package com.fasterxml.jackson.datatype.jsr310.old;
+
+import com.fasterxml.jackson.annotation.JsonTypeInfo;
+
+@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.WRAPPER_ARRAY, property = "@class")
+public interface MockObjectConfiguration
+{
+}
diff --git a/src/test/java/com/fasterxml/jackson/datatype/jsr310/old/ModuleTestBase.java b/src/test/java/com/fasterxml/jackson/datatype/jsr310/old/ModuleTestBase.java
new file mode 100644
index 00000000..e076fa95
--- /dev/null
+++ b/src/test/java/com/fasterxml/jackson/datatype/jsr310/old/ModuleTestBase.java
@@ -0,0 +1,12 @@
+package com.fasterxml.jackson.datatype.jsr310.old;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.datatype.jsr310.JSR310Module;
+
+public class ModuleTestBase
+{
+ protected ObjectMapper newMapper() {
+ return new ObjectMapper()
+ .registerModule(new JSR310Module());
+ }
+}
diff --git a/src/test/java/com/fasterxml/jackson/datatype/jsr310/old/PolymorphicTest.java b/src/test/java/com/fasterxml/jackson/datatype/jsr310/old/PolymorphicTest.java
new file mode 100644
index 00000000..76a70600
--- /dev/null
+++ b/src/test/java/com/fasterxml/jackson/datatype/jsr310/old/PolymorphicTest.java
@@ -0,0 +1,34 @@
+package com.fasterxml.jackson.datatype.jsr310.old;
+
+import java.time.ZoneId;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+public class PolymorphicTest extends ModuleTestBase
+{
+ private final ObjectMapper TYPING_MAPPER = newMapper();
+ {
+ TYPING_MAPPER.enableDefaultTyping();
+ }
+
+ // for [datatype-jsr310#24]
+ @Test
+ public void testZoneIdAsIs() throws Exception
+ {
+ ZoneId exp = ZoneId.of("America/Chicago");
+ String json = TYPING_MAPPER.writeValueAsString(exp);
+ assertEquals(exp, TYPING_MAPPER.readValue(json, ZoneId.class));
+ }
+
+ @Test
+ public void testZoneWithForcedBaseType() throws Exception
+ {
+ ZoneId exp = ZoneId.of("America/Chicago");
+ String json = TYPING_MAPPER.writerFor(ZoneId.class).writeValueAsString(exp);
+ assertEquals(exp, TYPING_MAPPER.readValue(json, ZoneId.class));
+ }
+}
diff --git a/src/test/java/com/fasterxml/jackson/datatype/jsr310/old/TestDecimalUtils.java b/src/test/java/com/fasterxml/jackson/datatype/jsr310/old/TestDecimalUtils.java
new file mode 100644
index 00000000..46b33c83
--- /dev/null
+++ b/src/test/java/com/fasterxml/jackson/datatype/jsr310/old/TestDecimalUtils.java
@@ -0,0 +1,123 @@
+package com.fasterxml.jackson.datatype.jsr310.old;
+
+import static org.junit.Assert.assertEquals;
+
+import java.math.BigDecimal;
+
+import com.fasterxml.jackson.datatype.jsr310.DecimalUtils;
+import org.junit.Test;
+
+public class TestDecimalUtils
+{
+ @Test
+ public void testToDecimal01()
+ {
+ String decimal = DecimalUtils.toDecimal(0, 0);
+
+ assertEquals("The returned decimal is not correct.", "0.000000000", decimal);
+ }
+
+ @Test
+ public void testToDecimal02()
+ {
+ String decimal = DecimalUtils.toDecimal(15, 72);
+
+ assertEquals("The returned decimal is not correct.", "15.000000072", decimal);
+ }
+
+ @Test
+ public void testToDecimal03()
+ {
+ String decimal = DecimalUtils.toDecimal(19827342231L, 192837465);
+
+ assertEquals("The returned decimal is not correct.", "19827342231.192837465", decimal);
+ }
+
+ @Test
+ public void testToDecimal04()
+ {
+ String decimal = DecimalUtils.toDecimal(19827342231L, 0);
+
+ assertEquals("The returned decimal is not correct.", "19827342231.000000000", decimal);
+ }
+
+ @Test
+ public void testToDecimal05()
+ {
+ String decimal = DecimalUtils.toDecimal(19827342231L, 999999999);
+
+ assertEquals("The returned decimal is not correct.", "19827342231.999999999", decimal);
+ }
+
+ @Test
+ public void testExtractNanosecondDecimal01()
+ {
+ BigDecimal value = new BigDecimal("0");
+
+ long seconds = value.longValue();
+ assertEquals("The second part is not correct.", 0L, seconds);
+
+ int nanoseconds = DecimalUtils.extractNanosecondDecimal(value, seconds);
+ assertEquals("The nanosecond part is not correct.", 0, nanoseconds);
+ }
+
+ @Test
+ public void testExtractNanosecondDecimal02()
+ {
+ BigDecimal value = new BigDecimal("15.000000072");
+
+ long seconds = value.longValue();
+ assertEquals("The second part is not correct.", 15L, seconds);
+
+ int nanoseconds = DecimalUtils.extractNanosecondDecimal(value, seconds);
+ assertEquals("The nanosecond part is not correct.", 72, nanoseconds);
+ }
+
+ @Test
+ public void testExtractNanosecondDecimal03()
+ {
+ BigDecimal value = new BigDecimal("15.72");
+
+ long seconds = value.longValue();
+ assertEquals("The second part is not correct.", 15L, seconds);
+
+ int nanoseconds = DecimalUtils.extractNanosecondDecimal(value, seconds);
+ assertEquals("The nanosecond part is not correct.", 720000000, nanoseconds);
+ }
+
+ @Test
+ public void testExtractNanosecondDecimal04()
+ {
+ BigDecimal value = new BigDecimal("19827342231.192837465");
+
+ long seconds = value.longValue();
+ assertEquals("The second part is not correct.", 19827342231L, seconds);
+
+ int nanoseconds = DecimalUtils.extractNanosecondDecimal(value, seconds);
+ assertEquals("The nanosecond part is not correct.", 192837465, nanoseconds);
+ }
+
+ @Test
+ public void testExtractNanosecondDecimal05()
+ {
+ BigDecimal value = new BigDecimal("19827342231");
+
+ long seconds = value.longValue();
+ assertEquals("The second part is not correct.", 19827342231L, seconds);
+
+ int nanoseconds = DecimalUtils.extractNanosecondDecimal(value, seconds);
+ assertEquals("The nanosecond part is not correct.", 0, nanoseconds);
+ }
+
+ @Test
+ public void testExtractNanosecondDecimal06()
+ {
+ BigDecimal value = new BigDecimal("19827342231.999999999");
+
+ long seconds = value.longValue();
+ assertEquals("The second part is not correct.", 19827342231L, seconds);
+
+ int nanoseconds = DecimalUtils.extractNanosecondDecimal(value, seconds);
+ assertEquals("The nanosecond part is not correct.", 999999999, nanoseconds);
+ }
+}
diff --git a/src/test/java/com/fasterxml/jackson/datatype/jsr310/old/TestDurationDeserialization.java b/src/test/java/com/fasterxml/jackson/datatype/jsr310/old/TestDurationDeserialization.java
new file mode 100644
index 00000000..967011e7
--- /dev/null
+++ b/src/test/java/com/fasterxml/jackson/datatype/jsr310/old/TestDurationDeserialization.java
@@ -0,0 +1,189 @@
+package com.fasterxml.jackson.datatype.jsr310.old;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.time.Duration;
+import java.time.temporal.TemporalAmount;
+
+import org.junit.Test;
+
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.ObjectReader;
+
+public class TestDurationDeserialization extends ModuleTestBase
+{
+ private final ObjectReader READER = newMapper().readerFor(Duration.class);
+
+ @Test
+ public void testDeserializationAsFloat01() throws Exception
+ {
+ Duration value = READER.with(DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS)
+ .readValue("60.0");
+
+ assertNotNull("The value should not be null.", value);
+ Duration exp = Duration.ofSeconds(60L, 0);
+ assertEquals("The value is not correct.", exp, value);
+ }
+
+ @Test
+ public void testDeserializationAsFloat02() throws Exception
+ {
+ Duration value = READER.without(DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS)
+ .readValue("60.0");
+
+ assertNotNull("The value should not be null.", value);
+ Duration exp = Duration.ofSeconds(60L, 0);
+ assertEquals("The value is not correct.", exp, value);
+ }
+
+ @Test
+ public void testDeserializationAsFloat03() throws Exception
+ {
+ Duration value = READER.with(DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS)
+ .readValue("13498.000008374");
+ assertNotNull("The value should not be null.", value);
+ assertEquals("The value is not correct.", Duration.ofSeconds(13498L, 8374), value);
+ }
+
+ @Test
+ public void testDeserializationAsFloat04() throws Exception
+ {
+ Duration value = READER.without(DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS)
+ .readValue("13498.000008374");
+ assertNotNull("The value should not be null.", value);
+ assertEquals("The value is not correct.", Duration.ofSeconds(13498L, 8374), value);
+ }
+
+ @Test
+ public void testDeserializationAsInt01() throws Exception
+ {
+ Duration value = READER.with(DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS)
+ .readValue("60");
+ assertNotNull("The value should not be null.", value);
+ assertEquals("The value is not correct.", Duration.ofSeconds(60L, 0), value);
+ }
+
+ @Test
+ public void testDeserializationAsInt02() throws Exception
+ {
+ Duration value = READER.without(DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS)
+ .readValue("60000");
+
+ assertNotNull("The value should not be null.", value);
+ assertEquals("The value is not correct.", Duration.ofSeconds(60L, 0), value);
+ }
+
+ @Test
+ public void testDeserializationAsInt03() throws Exception
+ {
+ Duration value = READER.with(DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS)
+ .readValue("13498");
+
+ assertNotNull("The value should not be null.", value);
+ assertEquals("The value is not correct.", Duration.ofSeconds(13498L, 0), value);
+ }
+
+ @Test
+ public void testDeserializationAsInt04() throws Exception
+ {
+ Duration value = READER.without(DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS)
+ .readValue("13498000");
+
+ assertNotNull("The value should not be null.", value);
+ assertEquals("The value is not correct.", Duration.ofSeconds(13498L, 0), value);
+ }
+
+ @Test
+ public void testDeserializationAsString01() throws Exception
+ {
+ Duration exp = Duration.ofSeconds(60L, 0);
+ Duration value = READER.readValue('"' + exp.toString() + '"');
+
+ assertNotNull("The value should not be null.", value);
+ assertEquals("The value is not correct.", exp, value);
+ }
+
+ @Test
+ public void testDeserializationAsString02() throws Exception
+ {
+ Duration exp = Duration.ofSeconds(13498L, 8374);
+ Duration value = READER.readValue('"' + exp.toString() + '"');
+
+ assertNotNull("The value should not be null.", value);
+ assertEquals("The value is not correct.", exp, value);
+ }
+
+ @Test
+ public void testDeserializationAsString03() throws Exception
+ {
+ Duration value = READER.readValue("\" \"");
+ assertNull("The value should be null.", value);
+ }
+
+ @Test
+ public void testDeserializationWithTypeInfo01() throws Exception
+ {
+ Duration duration = Duration.ofSeconds(13498L, 8374);
+
+ String prefix = "[\"" + Duration.class.getName() + "\",";
+
+ ObjectMapper mapper = newMapper();
+ mapper.configure(DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS, false);
+ mapper.addMixIn(TemporalAmount.class, MockObjectConfiguration.class);
+ TemporalAmount value = mapper.readValue(prefix + "13498.000008374]", TemporalAmount.class);
+
+ assertNotNull("The value should not be null.", value);
+ assertTrue("The value should be a Duration.", value instanceof Duration);
+ assertEquals("The value is not correct.", duration, value);
+ }
+
+ @Test
+ public void testDeserializationWithTypeInfo02() throws Exception
+ {
+ String prefix = "[\"" + Duration.class.getName() + "\",";
+
+ ObjectMapper mapper = newMapper();
+ mapper.configure(DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS, true);
+ mapper.addMixIn(TemporalAmount.class, MockObjectConfiguration.class);
+ TemporalAmount value = mapper.readValue(prefix + "13498]", TemporalAmount.class);
+
+ assertNotNull("The value should not be null.", value);
+ assertTrue("The value should be a Duration.", value instanceof Duration);
+ assertEquals("The value is not correct.", Duration.ofSeconds(13498L), value);
+ }
+
+ @Test
+ public void testDeserializationWithTypeInfo03() throws Exception
+ {
+ String prefix = "[\"" + Duration.class.getName() + "\",";
+
+ ObjectMapper mapper = newMapper();
+ mapper.configure(DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS, false);
+ mapper.addMixIn(TemporalAmount.class, MockObjectConfiguration.class);
+ TemporalAmount value = mapper.readValue(prefix + "13498837]", TemporalAmount.class);
+
+ assertNotNull("The value should not be null.", value);
+ assertTrue("The value should be a Duration.", value instanceof Duration);
+ assertEquals("The value is not correct.", Duration.ofSeconds(13498L, 837000000), value);
+ }
+
+ @Test
+ public void testDeserializationWithTypeInfo04() throws Exception
+ {
+ Duration duration = Duration.ofSeconds(13498L, 8374);
+
+ String prefix = "[\"" + Duration.class.getName() + "\",";
+
+ ObjectMapper mapper = newMapper();
+ mapper.addMixIn(TemporalAmount.class, MockObjectConfiguration.class);
+ TemporalAmount value = mapper.readValue(prefix + '"' + duration.toString() + "\"]", TemporalAmount.class);
+
+ assertNotNull("The value should not be null.", value);
+ assertTrue("The value should be a Duration.", value instanceof Duration);
+ assertEquals("The value is not correct.", duration, value);
+ }
+}
diff --git a/src/test/java/com/fasterxml/jackson/datatype/jsr310/old/TestDurationKeySerialization.java b/src/test/java/com/fasterxml/jackson/datatype/jsr310/old/TestDurationKeySerialization.java
new file mode 100644
index 00000000..0fa7d0d8
--- /dev/null
+++ b/src/test/java/com/fasterxml/jackson/datatype/jsr310/old/TestDurationKeySerialization.java
@@ -0,0 +1,59 @@
+package com.fasterxml.jackson.datatype.jsr310.old;
+
+import static org.junit.Assert.assertEquals;
+
+import java.time.Duration;
+import java.util.HashMap;
+import java.util.Map;
+
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.datatype.jsr310.JSR310Module;
+import org.junit.Before;
+import org.junit.Test;
+
+public class TestDurationKeySerialization {
+
+ private static final TypeReference