Skip to content

Commit 0ac0a6b

Browse files
SimpleDateFormat is not thread safe so we should create a new instance every time.
1 parent 1d83731 commit 0ac0a6b

3 files changed

Lines changed: 6 additions & 32 deletions

File tree

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>com.storakle.shopify</groupId>
88
<artifactId>shopify-api-java-wrapper</artifactId>
9-
<version>0.2.10</version>
9+
<version>0.2.11</version>
1010
<build>
1111
<sourceDirectory>src/main/java</sourceDirectory>
1212
<plugins>

src/main/java/com/storakle/shopify/jackson/FlexDateDeserializer.java

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,30 +21,17 @@ public final class FlexDateDeserializer extends JsonDeserializer<Date>
2121
@Override
2222
public Date deserialize(final JsonParser parser, final DeserializationContext context) throws IOException
2323
{
24+
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX");
25+
2426
final String date = parser.getText();
2527
try
2628
{
27-
return getFormatter().parse(date);
29+
return formatter.parse(date);
2830
}
2931
catch (final ParseException ex)
3032
{
3133
// Not worked, so let the default date serializer give it a try.
3234
return DateDeserializer.instance.deserialize(parser, context);
3335
}
3436
}
35-
36-
//
37-
//
38-
private static SimpleDateFormat getFormatter()
39-
{
40-
return FormatHolder.INSTANCE;
41-
}
42-
43-
/**
44-
*/
45-
private interface FormatHolder
46-
{
47-
SimpleDateFormat INSTANCE = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX");
48-
}
49-
5037
}

src/main/java/com/storakle/shopify/jackson/FlexDateSerializer.java

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,7 @@ public final class FlexDateSerializer extends JsonSerializer<Date>
1818
@Override
1919
public void serialize(final Date value, final JsonGenerator gen, final SerializerProvider arg2) throws IOException
2020
{
21-
gen.writeString(getFormatter().format(value));
22-
}
23-
24-
//
25-
//
26-
private static SimpleDateFormat getFormatter()
27-
{
28-
return FormatHolder.INSTANCE;
29-
}
30-
31-
/**
32-
*/
33-
private interface FormatHolder
34-
{
35-
SimpleDateFormat INSTANCE = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX");
21+
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX");
22+
gen.writeString(formatter.format(value));
3623
}
3724
}

0 commit comments

Comments
 (0)