Skip to content

Commit

Permalink
[RESTEASY-2422] Add system property for controlling SerializationFeat…
Browse files Browse the repository at this point in the history
…ure.WRITE_DURATIONS_AS_TIMESTAMPS
  • Loading branch information
asoldano committed Nov 21, 2019
1 parent 5adaa39 commit 51ab2fb
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
Expand Up @@ -49,6 +49,10 @@
@Produces({"application/json", "application/*+json", "text/json"})
public class ResteasyJackson2Provider extends JacksonJaxbJsonProvider
{
private static final boolean WRITE_DURATIONS_AS_TIMESTAMPS = getProperty(
"resteasy.jackson.serialization.writeDurationsAsTimestamps",
SerializationFeature.WRITE_DURATIONS_AS_TIMESTAMPS.enabledByDefault());

@Override
public boolean isReadable(Class<?> aClass, Type type, Annotation[] annotations, MediaType mediaType)
{
Expand Down Expand Up @@ -220,6 +224,7 @@ public void flush() throws IOException {
if (endpoint == null) {
ObjectMapper mapper = locateMapper(type, mediaType);
mapper.setPolymorphicTypeValidator(new WhiteListPolymorphicTypeValidatorBuilder().build());
mapper.configure(SerializationFeature.WRITE_DURATIONS_AS_TIMESTAMPS, WRITE_DURATIONS_AS_TIMESTAMPS);
endpoint = _configForWriting(mapper, annotations, null);

// and cache for future reuse
Expand Down Expand Up @@ -327,5 +332,18 @@ public Object run() throws Exception {
}
}


private static boolean getProperty(String propertyName, boolean def) {
final SecurityManager sm = System.getSecurityManager();
if (sm != null) {
return AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
@Override
public Boolean run() {
String p = System.getProperty(propertyName);
return p != null ? Boolean.valueOf(p) : def;
}
});
}
String p = System.getProperty(propertyName);
return p != null ? Boolean.valueOf(p) : def;
}
}
2 changes: 1 addition & 1 deletion testsuite/integration-tests/pom.xml
Expand Up @@ -42,7 +42,7 @@
<container.qualifier.manual.ssl.wildcard>jbossas-manual-ssl-wildcard</container.qualifier.manual.ssl.wildcard>
<container.qualifier.manual.ssl.sni>jbossas-manual-ssl-sni</container.qualifier.manual.ssl.sni>
<!-- https://issues.jboss.org/browse/RESTEASY-2411 -->
<additionalJvmArgs>-Dresteasy.jackson.deserialization.whitelist.allowIfBaseType.prefix=org.jboss.resteasy.test.providers.jackson2.whitelist.model.land -Dresteasy.jackson.deserialization.whitelist.allowIfSubType.prefix=org.jboss.resteasy.test.providers.jackson2.whitelist.model.land</additionalJvmArgs>
<additionalJvmArgs>-Dresteasy.jackson.deserialization.whitelist.allowIfBaseType.prefix=org.jboss.resteasy.test.providers.jackson2.whitelist.model.land -Dresteasy.jackson.deserialization.whitelist.allowIfSubType.prefix=org.jboss.resteasy.test.providers.jackson2.whitelist.model.land -Dresteasy.jackson.serialization.writeDurationsAsTimestamps=false</additionalJvmArgs>
</properties>

<artifactId>resteasy-integration-tests</artifactId>
Expand Down
Expand Up @@ -165,7 +165,7 @@ public void testDatatypeSupportedDate() throws Exception {
@Test
public void testDatatypeSupportedDuration() throws Exception {
String strResponse = requestHelper("duration", DEPLOYMENT_WITH_DATATYPE);
Assert.assertThat("Wrong conversion of Duration", strResponse, containsString("5.000000006"));
Assert.assertThat("Wrong conversion of Duration", strResponse, containsString("PT5.000000006S"));
}

/**
Expand Down

0 comments on commit 51ab2fb

Please sign in to comment.