mirror of https://github.com/jwtk/jjwt.git
Fixes for reviews. Hope i did not forget something.
This commit is contained in:
parent
bb1fb76ce9
commit
2bb8e4d02e
|
@ -1,6 +1,8 @@
|
|||
package io.jsonwebtoken.io;
|
||||
package io.jsonwebtoken.gson.io;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import io.jsonwebtoken.io.DeserializationException;
|
||||
import io.jsonwebtoken.io.Deserializer;
|
||||
import io.jsonwebtoken.lang.Assert;
|
||||
import java.io.IOException;
|
||||
|
|
@ -1,7 +1,10 @@
|
|||
package io.jsonwebtoken.io;
|
||||
package io.jsonwebtoken.gson.io;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import io.jsonwebtoken.io.Encoders;
|
||||
import io.jsonwebtoken.io.SerializationException;
|
||||
import io.jsonwebtoken.io.Serializer;
|
||||
import io.jsonwebtoken.lang.Assert;
|
||||
import io.jsonwebtoken.lang.Strings;
|
||||
|
||||
|
@ -24,8 +27,12 @@ public class GsonSerializer<T> implements Serializer<T> {
|
|||
@Override
|
||||
public byte[] serialize(T t) throws SerializationException {
|
||||
Assert.notNull(t, "Object to serialize cannot be null.");
|
||||
//Gson never throws any serialization exception
|
||||
try {
|
||||
return writeValueAsBytes(t);
|
||||
} catch (Exception e) {
|
||||
String msg = "Unable to serialize object: " + e.getMessage();
|
||||
throw new SerializationException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("WeakerAccess") //for testing
|
|
@ -34,8 +34,8 @@ public class RuntimeClasspathDeserializerLocator<T> implements InstanceLocator<D
|
|||
return Classes.newInstance("io.jsonwebtoken.io.JacksonDeserializer");
|
||||
} else if (isAvailable("io.jsonwebtoken.io.OrgJsonDeserializer")) {
|
||||
return Classes.newInstance("io.jsonwebtoken.io.OrgJsonDeserializer");
|
||||
} else if (isAvailable("io.jsonwebtoken.io.GsonDeserializer")) {
|
||||
return Classes.newInstance("io.jsonwebtoken.io.GsonDeserializer");
|
||||
} else if (isAvailable("io.jsonwebtoken.gson.io.GsonDeserializer")) {
|
||||
return Classes.newInstance("io.jsonwebtoken.gson.io.GsonDeserializer");
|
||||
} else {
|
||||
throw new IllegalStateException("Unable to discover any JSON Deserializer implementations on the classpath.");
|
||||
}
|
||||
|
|
|
@ -34,8 +34,8 @@ public class RuntimeClasspathSerializerLocator implements InstanceLocator<Serial
|
|||
return Classes.newInstance("io.jsonwebtoken.io.JacksonSerializer");
|
||||
} else if (isAvailable("io.jsonwebtoken.io.OrgJsonSerializer")) {
|
||||
return Classes.newInstance("io.jsonwebtoken.io.OrgJsonSerializer");
|
||||
} else if (isAvailable("io.jsonwebtoken.io.GsonSerializer")) {
|
||||
return Classes.newInstance("io.jsonwebtoken.io.GsonSerializer");
|
||||
} else if (isAvailable("io.jsonwebtoken.gson.io.GsonSerializer")) {
|
||||
return Classes.newInstance("io.jsonwebtoken.gson.io.GsonSerializer");
|
||||
} else {
|
||||
throw new IllegalStateException("Unable to discover any JSON Serializer implementations on the classpath.");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue