From 1b5b89304a7e38439951a0d67696260435de3021 Mon Sep 17 00:00:00 2001 From: Francois JACQUES Date: Wed, 9 Jan 2019 19:51:12 +0100 Subject: [PATCH] Fixes #397 : avoid dependency side effect to affect choice of json serializer/deserializer. --- .../impl/io/RuntimeClasspathDeserializerLocator.java | 4 ++-- .../impl/io/RuntimeClasspathSerializerLocator.java | 4 ++-- .../impl/io/RuntimeClasspathDeserializerLocatorTest.groovy | 2 +- .../impl/io/RuntimeClasspathSerializerLocatorTest.groovy | 3 +-- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/impl/src/main/java/io/jsonwebtoken/impl/io/RuntimeClasspathDeserializerLocator.java b/impl/src/main/java/io/jsonwebtoken/impl/io/RuntimeClasspathDeserializerLocator.java index 61d2dac7..034fe34e 100644 --- a/impl/src/main/java/io/jsonwebtoken/impl/io/RuntimeClasspathDeserializerLocator.java +++ b/impl/src/main/java/io/jsonwebtoken/impl/io/RuntimeClasspathDeserializerLocator.java @@ -30,9 +30,9 @@ public class RuntimeClasspathDeserializerLocator implements InstanceLocator 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."); diff --git a/impl/src/main/java/io/jsonwebtoken/impl/io/RuntimeClasspathSerializerLocator.java b/impl/src/main/java/io/jsonwebtoken/impl/io/RuntimeClasspathSerializerLocator.java index 63a6137d..c2efbfd1 100644 --- a/impl/src/main/java/io/jsonwebtoken/impl/io/RuntimeClasspathSerializerLocator.java +++ b/impl/src/main/java/io/jsonwebtoken/impl/io/RuntimeClasspathSerializerLocator.java @@ -30,9 +30,9 @@ public class RuntimeClasspathSerializerLocator implements InstanceLocator 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."); diff --git a/impl/src/test/groovy/io/jsonwebtoken/impl/io/RuntimeClasspathDeserializerLocatorTest.groovy b/impl/src/test/groovy/io/jsonwebtoken/impl/io/RuntimeClasspathDeserializerLocatorTest.groovy index 22756feb..7013aa2a 100644 --- a/impl/src/test/groovy/io/jsonwebtoken/impl/io/RuntimeClasspathDeserializerLocatorTest.groovy +++ b/impl/src/test/groovy/io/jsonwebtoken/impl/io/RuntimeClasspathDeserializerLocatorTest.groovy @@ -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) diff --git a/impl/src/test/groovy/io/jsonwebtoken/impl/io/RuntimeClasspathSerializerLocatorTest.groovy b/impl/src/test/groovy/io/jsonwebtoken/impl/io/RuntimeClasspathSerializerLocatorTest.groovy index 2e6c2aef..96daae90 100644 --- a/impl/src/test/groovy/io/jsonwebtoken/impl/io/RuntimeClasspathSerializerLocatorTest.groovy +++ b/impl/src/test/groovy/io/jsonwebtoken/impl/io/RuntimeClasspathSerializerLocatorTest.groovy @@ -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 @@ -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)