2828import com .auth0 .authentication .result .Credentials ;
2929import com .auth0 .authentication .result .DatabaseUser ;
3030import com .auth0 .authentication .result .Delegation ;
31+ import com .auth0 .authentication .result .JsonRequiredTypeAdapterFactory ;
3132import com .auth0 .authentication .result .UserProfile ;
3233import com .auth0 .request .AuthenticationRequest ;
3334import com .auth0 .request .ParameterizableRequest ;
3435import com .auth0 .request .Request ;
3536import com .auth0 .request .internal .RequestFactory ;
3637import com .auth0 .util .Telemetry ;
37- import com .fasterxml .jackson .databind .ObjectMapper ;
38+ import com .google .gson .Gson ;
39+ import com .google .gson .GsonBuilder ;
3840import com .squareup .okhttp .HttpUrl ;
3941import com .squareup .okhttp .OkHttpClient ;
4042
@@ -77,7 +79,7 @@ public class AuthenticationAPIClient {
7779
7880 private final Auth0 auth0 ;
7981 private final OkHttpClient client ;
80- private final ObjectMapper mapper ;
82+ private final Gson gson ;
8183 private final RequestFactory factory ;
8284
8385 private String defaultDatabaseConnection = DEFAULT_DB_CONNECTION ;
@@ -88,13 +90,13 @@ public class AuthenticationAPIClient {
8890 * @param auth0 account information
8991 */
9092 public AuthenticationAPIClient (Auth0 auth0 ) {
91- this (auth0 , new OkHttpClient (), new ObjectMapper ());
93+ this (auth0 , new OkHttpClient (), buildGson ());
9294 }
9395
94- private AuthenticationAPIClient (Auth0 auth0 , OkHttpClient client , ObjectMapper mapper ) {
96+ private AuthenticationAPIClient (Auth0 auth0 , OkHttpClient client , Gson gson ) {
9597 this .auth0 = auth0 ;
9698 this .client = client ;
97- this .mapper = mapper ;
99+ this .gson = gson ;
98100 this .factory = new RequestFactory ();
99101 final Telemetry telemetry = auth0 .getTelemetry ();
100102 if (telemetry != null ) {
@@ -187,7 +189,7 @@ public AuthenticationRequest loginWithOAuthAccessToken(String token, String conn
187189 .setAccessToken (token )
188190 .asDictionary ();
189191
190- return factory .authenticationPOST (url , client , mapper )
192+ return factory .authenticationPOST (url , client , gson )
191193 .addAuthenticationParameters (parameters );
192194 }
193195
@@ -304,7 +306,7 @@ public DatabaseConnectionRequest<DatabaseUser> createUser(String email, String p
304306 .setConnection (defaultDatabaseConnection )
305307 .setClientId (getClientId ())
306308 .asDictionary ();
307- final ParameterizableRequest <DatabaseUser > request = factory .POST (url , client , mapper , DatabaseUser .class )
309+ final ParameterizableRequest <DatabaseUser > request = factory .POST (url , client , gson , DatabaseUser .class )
308310 .addParameters (parameters );
309311 return new DatabaseConnectionRequest <>(request );
310312 }
@@ -413,7 +415,7 @@ public DatabaseConnectionRequest<Void> requestChangePassword(String email) {
413415 .setClientId (getClientId ())
414416 .setConnection (defaultDatabaseConnection )
415417 .asDictionary ();
416- final ParameterizableRequest <Void > request = factory .POST (url , client , mapper )
418+ final ParameterizableRequest <Void > request = factory .POST (url , client , gson )
417419 .addParameters (parameters );
418420 return new DatabaseConnectionRequest <>(request );
419421 }
@@ -524,7 +526,7 @@ public Request<Void> unlink(String userId, String accessToken) {
524526 .set (USER_ID_KEY , userId )
525527 .asDictionary ();
526528
527- return factory .POST (url , client , mapper )
529+ return factory .POST (url , client , gson )
528530 .addParameters (parameters );
529531 }
530532
@@ -612,7 +614,7 @@ public ParameterizableRequest<Map<String, Object>> delegation() {
612614 .setClientId (getClientId ())
613615 .setGrantType (ParameterBuilder .GRANT_TYPE_JWT )
614616 .asDictionary ();
615- return factory .rawPOST (url , client , mapper )
617+ return factory .rawPOST (url , client , gson )
616618 .addParameters (parameters );
617619 }
618620
@@ -626,7 +628,7 @@ protected <T> ParameterizableRequest<T> delegation(Class<T> clazz) {
626628 .setGrantType (ParameterBuilder .GRANT_TYPE_JWT )
627629 .asDictionary ();
628630
629- return factory .POST (url , client , mapper , clazz )
631+ return factory .POST (url , client , gson , clazz )
630632 .addParameters (parameters );
631633 }
632634
@@ -644,7 +646,7 @@ public ParameterizableRequest<Void> passwordless() {
644646 final Map <String , Object > parameters = ParameterBuilder .newBuilder ()
645647 .setClientId (getClientId ())
646648 .asDictionary ();
647- return factory .POST (url , client , mapper )
649+ return factory .POST (url , client , gson )
648650 .addParameters (parameters );
649651 }
650652
@@ -671,7 +673,7 @@ private AuthenticationRequest loginWithResourceOwner(Map<String, Object> paramet
671673 .setConnection (defaultDatabaseConnection )
672674 .addAll (parameters )
673675 .asDictionary ();
674- return factory .authenticationPOST (url , client , mapper )
676+ return factory .authenticationPOST (url , client , gson )
675677 .addAuthenticationParameters (requestParameters );
676678 }
677679
@@ -680,7 +682,7 @@ private ParameterizableRequest<UserProfile> profileRequest() {
680682 .addPathSegment (TOKEN_INFO_PATH )
681683 .build ();
682684
683- return factory .POST (url , client , mapper , UserProfile .class );
685+ return factory .POST (url , client , gson , UserProfile .class );
684686 }
685687
686688 /**
@@ -705,7 +707,13 @@ public AuthenticationRequest token(String authorizationCode, String codeVerifier
705707 .addPathSegment (TOKEN_PATH )
706708 .build ();
707709
708- return factory .authenticationPOST (url , client , mapper )
710+ return factory .authenticationPOST (url , client , gson )
709711 .addAuthenticationParameters (parameters );
710712 }
713+
714+ static Gson buildGson () {
715+ return new GsonBuilder ()
716+ .registerTypeAdapterFactory (new JsonRequiredTypeAdapterFactory ())
717+ .create ();
718+ }
711719}
0 commit comments