mirror of https://github.com/jwtk/jjwt.git
Fixes #397 : avoid dependency side effect to affect choice of json serializer/deserializer.
This commit is contained in:
parent
70e6845b82
commit
1b5b89304a
|
@ -30,9 +30,9 @@ public class RuntimeClasspathDeserializerLocator<T> implements InstanceLocator<D
|
||||||
|
|
||||||
@SuppressWarnings("WeakerAccess") //to allow testing override
|
@SuppressWarnings("WeakerAccess") //to allow testing override
|
||||||
protected Deserializer<T> locate() {
|
protected Deserializer<T> locate() {
|
||||||
if (isAvailable("com.fasterxml.jackson.databind.ObjectMapper")) {
|
if (isAvailable("io.jsonwebtoken.io.JacksonDeserializer")) {
|
||||||
return Classes.newInstance("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");
|
return Classes.newInstance("io.jsonwebtoken.io.OrgJsonDeserializer");
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalStateException("Unable to discover any JSON Deserializer implementations on the classpath.");
|
throw new IllegalStateException("Unable to discover any JSON Deserializer implementations on the classpath.");
|
||||||
|
|
|
@ -30,9 +30,9 @@ public class RuntimeClasspathSerializerLocator implements InstanceLocator<Serial
|
||||||
|
|
||||||
@SuppressWarnings("WeakerAccess") //to allow testing override
|
@SuppressWarnings("WeakerAccess") //to allow testing override
|
||||||
protected Serializer<Object> locate() {
|
protected Serializer<Object> locate() {
|
||||||
if (isAvailable("com.fasterxml.jackson.databind.ObjectMapper")) {
|
if (isAvailable("io.jsonwebtoken.io.JacksonSerializer")) {
|
||||||
return Classes.newInstance("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");
|
return Classes.newInstance("io.jsonwebtoken.io.OrgJsonSerializer");
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalStateException("Unable to discover any JSON Serializer implementations on the classpath.");
|
throw new IllegalStateException("Unable to discover any JSON Serializer implementations on the classpath.");
|
||||||
|
|
|
@ -86,7 +86,7 @@ class RuntimeClasspathDeserializerLocatorTest {
|
||||||
def locator = new RuntimeClasspathDeserializerLocator() {
|
def locator = new RuntimeClasspathDeserializerLocator() {
|
||||||
@Override
|
@Override
|
||||||
protected boolean isAvailable(String fqcn) {
|
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 false; //skip it to allow the OrgJson impl to be created
|
||||||
}
|
}
|
||||||
return super.isAvailable(fqcn)
|
return super.isAvailable(fqcn)
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package io.jsonwebtoken.impl.io
|
package io.jsonwebtoken.impl.io
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper
|
|
||||||
import io.jsonwebtoken.io.Serializer
|
import io.jsonwebtoken.io.Serializer
|
||||||
import io.jsonwebtoken.io.JacksonSerializer
|
import io.jsonwebtoken.io.JacksonSerializer
|
||||||
import io.jsonwebtoken.io.OrgJsonSerializer
|
import io.jsonwebtoken.io.OrgJsonSerializer
|
||||||
|
@ -86,7 +85,7 @@ class RuntimeClasspathSerializerLocatorTest {
|
||||||
def locator = new RuntimeClasspathSerializerLocator() {
|
def locator = new RuntimeClasspathSerializerLocator() {
|
||||||
@Override
|
@Override
|
||||||
protected boolean isAvailable(String fqcn) {
|
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 false //skip it to allow the OrgJson impl to be created
|
||||||
}
|
}
|
||||||
return super.isAvailable(fqcn)
|
return super.isAvailable(fqcn)
|
||||||
|
|
Loading…
Reference in New Issue