-
Notifications
You must be signed in to change notification settings - Fork 123
Optimize InstantDeserializer
addInColonToOffsetIfMissing()
#336
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
import java.time.temporal.ChronoField; | ||
import java.time.temporal.ChronoUnit; | ||
import java.time.temporal.Temporal; | ||
import java.util.Arrays; | ||
import java.util.Map; | ||
import java.util.TimeZone; | ||
|
||
|
@@ -811,6 +812,40 @@ public void testOffsetDateTimeMinOrMax() throws Exception | |
_testOffsetDateTimeMinOrMax(OffsetDateTime.MAX); | ||
} | ||
|
||
@Test | ||
public void OffsetDateTime_with_offset_can_be_deserialized() throws Exception { | ||
Comment on lines
+815
to
+816
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems like we can merge this and one for zonedDateTime below into a separate test class like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, I can consolidate these into a separate test class There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this case, I think keeping them along with existing test makes sense: this is not new functionality but optimizing (and adding test coverage). So let's not create per-issue test classes. |
||
ObjectReader r = MAPPER.readerFor(OffsetDateTime.class) | ||
.without(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE); | ||
|
||
String base = "2015-07-24T12:23:34.184"; | ||
for (String offset : Arrays.asList("+00", "-00")) { | ||
String time = base + offset; | ||
if (!System.getProperty("java.version").startsWith("1.8")) { | ||
// JDK 8 cannot parse hour offsets without minutes | ||
assertIsEqual(OffsetDateTime.parse("2015-07-24T12:23:34.184Z"), r.readValue('"' + time + '"')); | ||
} | ||
assertIsEqual(OffsetDateTime.parse("2015-07-24T12:23:34.184Z"), r.readValue('"' + time + "00" + '"')); | ||
assertIsEqual(OffsetDateTime.parse("2015-07-24T12:23:34.184Z"), r.readValue('"' + time + ":00" + '"')); | ||
assertIsEqual(OffsetDateTime.parse("2015-07-24T12:23:34.184" + offset + ":30"), r.readValue('"' + time + "30" + '"')); | ||
assertIsEqual(OffsetDateTime.parse("2015-07-24T12:23:34.184" + offset + ":30"), r.readValue('"' + time + ":30" + '"')); | ||
} | ||
|
||
for (String prefix : Arrays.asList("-", "+")) { | ||
for (String hours : Arrays.asList("00", "01", "02", "03", "11", "12")) { | ||
String time = base + prefix + hours; | ||
OffsetDateTime expectedHour = OffsetDateTime.parse(time + ":00"); | ||
if (!System.getProperty("java.version").startsWith("1.8")) { | ||
// JDK 8 cannot parse hour offsets without minutes | ||
assertIsEqual(expectedHour, r.readValue('"' + time + '"')); | ||
} | ||
assertIsEqual(expectedHour, r.readValue('"' + time + "00" + '"')); | ||
assertIsEqual(expectedHour, r.readValue('"' + time + ":00" + '"')); | ||
assertIsEqual(OffsetDateTime.parse(time + ":30"), r.readValue('"' + time + "30" + '"')); | ||
assertIsEqual(OffsetDateTime.parse(time + ":30"), r.readValue('"' + time + ":30" + '"')); | ||
} | ||
} | ||
} | ||
|
||
private void _testOffsetDateTimeMinOrMax(OffsetDateTime offsetDateTime) | ||
throws Exception | ||
{ | ||
|
Uh oh!
There was an error while loading. Please reload this page.