Skip to content

Commit

Permalink
Fixes #397 : avoid dependency side effect to affect choice of json se…
Browse files Browse the repository at this point in the history
…rializer/deserializer.
  • Loading branch information
hypnoce committed Mar 10, 2019
1 parent af73a02 commit dba2262
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ public Deserializer<T> getInstance() {

@SuppressWarnings("WeakerAccess") //to allow testing override
protected Deserializer<T> locate() {
if (isAvailable("com.fasterxml.jackson.databind.ObjectMapper")) {
if (isAvailable("io.jsonwebtoken.io.JacksonDeserializer")) {
return Classes.newInstance("io.jsonwebtoken.io.JacksonDeserializer");
} else if (isAvailable("org.json.JSONObject")) {
} else if (isAvailable("io.jsonwebtoken.io.OrgJsonDeserializer")) {
return Classes.newInstance("io.jsonwebtoken.io.OrgJsonDeserializer");
} else {
throw new IllegalStateException("Unable to discover any JSON Deserializer implementations on the classpath.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ public Serializer<Object> getInstance() {

@SuppressWarnings("WeakerAccess") //to allow testing override
protected Serializer<Object> locate() {
if (isAvailable("com.fasterxml.jackson.databind.ObjectMapper")) {
if (isAvailable("io.jsonwebtoken.io.JacksonSerializer")) {
return Classes.newInstance("io.jsonwebtoken.io.JacksonSerializer");
} else if (isAvailable("org.json.JSONObject")) {
} else if (isAvailable("io.jsonwebtoken.io.OrgJsonSerializer")) {
return Classes.newInstance("io.jsonwebtoken.io.OrgJsonSerializer");
} else {
throw new IllegalStateException("Unable to discover any JSON Serializer implementations on the classpath.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class RuntimeClasspathDeserializerLocatorTest {
def locator = new RuntimeClasspathDeserializerLocator() {
@Override
protected boolean isAvailable(String fqcn) {
if (ObjectMapper.class.getName().equals(fqcn)) {
if (JacksonDeserializer.class.getName().equals(fqcn)) {
return false; //skip it to allow the OrgJson impl to be created
}
return super.isAvailable(fqcn)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.jsonwebtoken.impl.io

import com.fasterxml.jackson.databind.ObjectMapper
import io.jsonwebtoken.io.Serializer
import io.jsonwebtoken.io.JacksonSerializer
import io.jsonwebtoken.io.OrgJsonSerializer
Expand Down Expand Up @@ -86,7 +85,7 @@ class RuntimeClasspathSerializerLocatorTest {
def locator = new RuntimeClasspathSerializerLocator() {
@Override
protected boolean isAvailable(String fqcn) {
if (ObjectMapper.class.getName().equals(fqcn)) {
if (JacksonSerializer.class.getName().equals(fqcn)) {
return false //skip it to allow the OrgJson impl to be created
}
return super.isAvailable(fqcn)
Expand Down

0 comments on commit dba2262

Please sign in to comment.