Skip to content
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

fix(all): Don't return incorrect date format instance #3576

Merged
merged 2 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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