Skip to content

Commit

Permalink
SimpleDateFormat is not thread safe so we should create a new instanc…
Browse files Browse the repository at this point in the history
…e every time.
  • Loading branch information
ivanst-stoyanov committed Nov 2, 2017
1 parent 1d83731 commit 0ac0a6b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 32 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.storakle.shopify</groupId>
<artifactId>shopify-api-java-wrapper</artifactId>
<version>0.2.10</version>
<version>0.2.11</version>
<build>
<sourceDirectory>src/main/java</sourceDirectory>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,17 @@ public final class FlexDateDeserializer extends JsonDeserializer<Date>
@Override
public Date deserialize(final JsonParser parser, final DeserializationContext context) throws IOException
{
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX");

final String date = parser.getText();
try
{
return getFormatter().parse(date);
return formatter.parse(date);
}
catch (final ParseException ex)
{
// Not worked, so let the default date serializer give it a try.
return DateDeserializer.instance.deserialize(parser, context);
}
}

//
//
private static SimpleDateFormat getFormatter()
{
return FormatHolder.INSTANCE;
}

/**
*/
private interface FormatHolder
{
SimpleDateFormat INSTANCE = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX");
}

}
17 changes: 2 additions & 15 deletions src/main/java/com/storakle/shopify/jackson/FlexDateSerializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,7 @@ public final class FlexDateSerializer extends JsonSerializer<Date>
@Override
public void serialize(final Date value, final JsonGenerator gen, final SerializerProvider arg2) throws IOException
{
gen.writeString(getFormatter().format(value));
}

//
//
private static SimpleDateFormat getFormatter()
{
return FormatHolder.INSTANCE;
}

/**
*/
private interface FormatHolder
{
SimpleDateFormat INSTANCE = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX");
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX");
gen.writeString(formatter.format(value));
}
}

0 comments on commit 0ac0a6b

Please sign in to comment.