Fixes for reviews. Hope i did not forget something.

This commit is contained in:
patton73 2019-07-17 22:46:18 +02:00
parent bb1fb76ce9
commit 2bb8e4d02e
9 changed files with 24 additions and 15 deletions

View File

@ -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;

View File

@ -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
return writeValueAsBytes(t);
try {
return writeValueAsBytes(t);
} catch (Exception e) {
String msg = "Unable to serialize object: " + e.getMessage();
throw new SerializationException(msg, e);
}
}
@SuppressWarnings("WeakerAccess") //for testing

View File

@ -36,7 +36,7 @@
<modules>
<module>jackson</module>
<module>orgjson</module>
<module>gson</module>
<module>gson</module>
</modules>
</project>

View File

@ -54,11 +54,11 @@
<artifactId>jjwt-orgjson</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-gson</artifactId>
<scope>test</scope>
</dependency>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View File

@ -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.");
}

View File

@ -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.");
}

View File

@ -90,7 +90,7 @@
<jackson.version>2.9.9.1</jackson.version>
<orgjson.version>20180130</orgjson.version>
<gson.version>2.8.5</gson.version>
<gson.version>2.8.5</gson.version>
<!-- Optional Runtime Dependencies: -->
<bouncycastle.version>1.60</bouncycastle.version>
@ -132,7 +132,7 @@
<artifactId>jjwt-orgjson</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-gson</artifactId>
<version>${project.version}</version>
@ -147,7 +147,7 @@
<artifactId>json</artifactId>
<version>${orgjson.version}</version>
</dependency>
<dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>${gson.version}</version>