Skip to content

Commit

Permalink
Support IsoFields and JulianFields.
Browse files Browse the repository at this point in the history
  • Loading branch information
joehni committed Feb 18, 2017
1 parent b81fd21 commit 788fda1
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
6 changes: 6 additions & 0 deletions xstream/src/java/com/thoughtworks/xstream/XStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,9 @@ protected void setupAliases() {
alias("year-month", JVM.loadClassForName("java.time.YearMonth"));
alias("zoned-date-time", JVM.loadClassForName("java.time.ZonedDateTime"));
aliasType("zone-id", JVM.loadClassForName("java.time.ZoneId"));
alias("iso-field", JVM.loadClassForName("java.time.temporal.IsoFields$Field"));
alias("iso-unit", JVM.loadClassForName("java.time.temporal.IsoFields$Unit"));
alias("julian-field", JVM.loadClassForName("java.time.temporal.JulianFields$Field"));
}

aliasType("charset", Charset.class);
Expand Down Expand Up @@ -1008,6 +1011,9 @@ protected void setupImmutableTypes() {
addImmutableTypeDynamically("java.time.ZoneId", false);
addImmutableTypeDynamically("java.time.ZoneOffset", false);
addImmutableTypeDynamically("java.time.ZoneRegion", false);
addImmutableTypeDynamically("java.time.temporal.IsoFields$Field", false);
addImmutableTypeDynamically("java.time.temporal.IsoFields$Unit", false);
addImmutableTypeDynamically("java.time.temporal.JulianFields$Field", false);
}
}

Expand Down
41 changes: 41 additions & 0 deletions xstream/src/test/com/thoughtworks/acceptance/Time18TypesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.temporal.IsoFields;
import java.time.temporal.JulianFields;
import java.time.temporal.TemporalField;


/**
Expand Down Expand Up @@ -510,4 +513,42 @@ public void testZoneRegionIsImmutable() {
+ " <zone-id>Europe/Rome</zone-id>\n" //
+ "</zone-id-array>");
}

public void testIsoFields() {
assertBothWays(IsoFields.DAY_OF_QUARTER, "<iso-field>DAY_OF_QUARTER</iso-field>");
assertBothWays(IsoFields.QUARTER_OF_YEAR, "<iso-field>QUARTER_OF_YEAR</iso-field>");
assertBothWays(IsoFields.QUARTER_YEARS, "<iso-unit>QUARTER_YEARS</iso-unit>");
assertBothWays(IsoFields.WEEK_BASED_YEAR, "<iso-field>WEEK_BASED_YEAR</iso-field>");
assertBothWays(IsoFields.WEEK_BASED_YEARS, "<iso-unit>WEEK_BASED_YEARS</iso-unit>");
assertBothWays(IsoFields.WEEK_OF_WEEK_BASED_YEAR, "<iso-field>WEEK_OF_WEEK_BASED_YEAR</iso-field>");
}

public void testIsoFieldsAreImmutable() {
final Object[] array = new Object[4];
array[0] = array[1] = IsoFields.DAY_OF_QUARTER;
array[2] = array[3] = IsoFields.QUARTER_YEARS;
assertBothWays(array, "" //
+ "<object-array>\n" //
+ " <iso-field>DAY_OF_QUARTER</iso-field>\n" //
+ " <iso-field>DAY_OF_QUARTER</iso-field>\n" //
+ " <iso-unit>QUARTER_YEARS</iso-unit>\n" //
+ " <iso-unit>QUARTER_YEARS</iso-unit>\n" //
+ "</object-array>");
}

public void testJulianFields() {
assertBothWays(JulianFields.JULIAN_DAY, "<julian-field>JULIAN_DAY</julian-field>");
assertBothWays(JulianFields.MODIFIED_JULIAN_DAY, "<julian-field>MODIFIED_JULIAN_DAY</julian-field>");
assertBothWays(JulianFields.RATA_DIE, "<julian-field>RATA_DIE</julian-field>");
}

public void testJulianFieldsAreImmutable() {
final TemporalField[] array = new TemporalField[2];
array[0] = array[1] = JulianFields.JULIAN_DAY;
assertBothWays(array, "" //
+ "<java.time.temporal.TemporalField-array>\n" //
+ " <julian-field>JULIAN_DAY</julian-field>\n" //
+ " <julian-field>JULIAN_DAY</julian-field>\n" //
+ "</java.time.temporal.TemporalField-array>");
}
}

0 comments on commit 788fda1

Please sign in to comment.