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 com.google.gson.Gson;
import io.jsonwebtoken.io.DeserializationException;
import io.jsonwebtoken.io.Deserializer;
import io.jsonwebtoken.lang.Assert; import io.jsonwebtoken.lang.Assert;
import java.io.IOException; 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.Gson;
import com.google.gson.GsonBuilder; 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.Assert;
import io.jsonwebtoken.lang.Strings; import io.jsonwebtoken.lang.Strings;
@ -24,8 +27,12 @@ public class GsonSerializer<T> implements Serializer<T> {
@Override @Override
public byte[] serialize(T t) throws SerializationException { public byte[] serialize(T t) throws SerializationException {
Assert.notNull(t, "Object to serialize cannot be null."); Assert.notNull(t, "Object to serialize cannot be null.");
//Gson never throws any serialization exception try {
return writeValueAsBytes(t); return writeValueAsBytes(t);
} catch (Exception e) {
String msg = "Unable to serialize object: " + e.getMessage();
throw new SerializationException(msg, e);
}
} }
@SuppressWarnings("WeakerAccess") //for testing @SuppressWarnings("WeakerAccess") //for testing

View File

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

View File

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

View File

@ -34,8 +34,8 @@ public class RuntimeClasspathDeserializerLocator<T> implements InstanceLocator<D
return Classes.newInstance("io.jsonwebtoken.io.JacksonDeserializer"); return Classes.newInstance("io.jsonwebtoken.io.JacksonDeserializer");
} else if (isAvailable("io.jsonwebtoken.io.OrgJsonDeserializer")) { } else if (isAvailable("io.jsonwebtoken.io.OrgJsonDeserializer")) {
return Classes.newInstance("io.jsonwebtoken.io.OrgJsonDeserializer"); return Classes.newInstance("io.jsonwebtoken.io.OrgJsonDeserializer");
} else if (isAvailable("io.jsonwebtoken.io.GsonDeserializer")) { } else if (isAvailable("io.jsonwebtoken.gson.io.GsonDeserializer")) {
return Classes.newInstance("io.jsonwebtoken.io.GsonDeserializer"); return Classes.newInstance("io.jsonwebtoken.gson.io.GsonDeserializer");
} 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.");
} }

View File

@ -34,8 +34,8 @@ public class RuntimeClasspathSerializerLocator implements InstanceLocator<Serial
return Classes.newInstance("io.jsonwebtoken.io.JacksonSerializer"); return Classes.newInstance("io.jsonwebtoken.io.JacksonSerializer");
} else if (isAvailable("io.jsonwebtoken.io.OrgJsonSerializer")) { } else if (isAvailable("io.jsonwebtoken.io.OrgJsonSerializer")) {
return Classes.newInstance("io.jsonwebtoken.io.OrgJsonSerializer"); return Classes.newInstance("io.jsonwebtoken.io.OrgJsonSerializer");
} else if (isAvailable("io.jsonwebtoken.io.GsonSerializer")) { } else if (isAvailable("io.jsonwebtoken.gson.io.GsonSerializer")) {
return Classes.newInstance("io.jsonwebtoken.io.GsonSerializer"); return Classes.newInstance("io.jsonwebtoken.gson.io.GsonSerializer");
} 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.");
} }

View File

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