Skip to content

Commit

Permalink
fix: drop reflective access warnings to java.time.* classes (#596)
Browse files Browse the repository at this point in the history
Java module system gives warnings on reflective access to java.time.*
private fields, which are performed by Jackson when using
TwilioRestClient.

Jackson provides a `JavaTimeModule` which configures an ObjectMapper to
use public methods instead of reflective access to private fields in
classes in java.time.

This PR adds the dependency for `JavaTimeModule` and adds it to the
ObjectMapper created by `TwilioRestClient`, which removes all the
warnings that I have seen.
  • Loading branch information
mjg123 authored Oct 12, 2020
1 parent 6ae280b commit 1b1387d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,11 @@
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/com/twilio/http/TwilioRestClient.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.twilio.http;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;

import java.util.function.Predicate;

Expand All @@ -27,6 +28,12 @@ private TwilioRestClient(Builder b) {
this.edge = b.edge;
this.httpClient = b.httpClient;
this.objectMapper = new ObjectMapper();

// This module configures the ObjectMapper to use
// public API methods for manipulating java.time.*
// classes. The alternative is to use reflection which
// generates warnings from the module system on Java 9+
objectMapper.registerModule(new JavaTimeModule());
}

/**
Expand Down

0 comments on commit 1b1387d

Please sign in to comment.