Skip to content

Commit

Permalink
Don't return incorrect date format instance (#3576)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattcreaser committed May 16, 2024
1 parent 62a5fb4 commit d9231da
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ public static ByteJsonUnmarshaller getInstance() {
*/
public static class DateJsonUnmarshaller implements Unmarshaller<Date, JsonUnmarshallerContext> {
private static final int DATE_MULTIPLIER = 1000;
private final TimestampFormat format;
final TimestampFormat format;

private DateJsonUnmarshaller(TimestampFormat format) {
this.format = format;
Expand Down Expand Up @@ -286,10 +286,7 @@ public Date unmarshall(JsonUnmarshallerContext unmarshallerContext) throws Excep
* @return the instance.
*/
public static DateJsonUnmarshaller getInstance() {
if (instance == null) {
instance = new DateJsonUnmarshaller(TimestampFormat.UNIX_TIMESTAMP);
}
return instance;
return getInstance(TimestampFormat.UNIX_TIMESTAMP);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,15 @@ public void testDateRfc822JsonUnmarshaller() throws Exception {
assertEquals(unmarshalledDate.getTime(), date.getTime());
}

@Test
public void defaultFunctionAlwaysReturnsUnixTimestampUnmarshaller() {
SimpleTypeJsonUnmarshallers.DateJsonUnmarshaller first =
SimpleTypeJsonUnmarshallers.DateJsonUnmarshaller.getInstance(TimestampFormat.ISO_8601);
SimpleTypeJsonUnmarshallers.DateJsonUnmarshaller second =
SimpleTypeJsonUnmarshallers.DateJsonUnmarshaller.getInstance();
assertEquals(TimestampFormat.UNIX_TIMESTAMP, second.format);
}

@Test
public void testDoubleJsonUnmarshaller() throws Exception {
Double dub = new Double(5.5);
Expand Down

0 comments on commit d9231da

Please sign in to comment.