diff --git a/implementation/pom.xml b/implementation/pom.xml
index 9726002c..a6fd9bdf 100644
--- a/implementation/pom.xml
+++ b/implementation/pom.xml
@@ -123,6 +123,17 @@
1.0.0-SNAPSHOT
test
+
+ jakarta.json.bind
+ jakarta.json.bind-api
+ test
+
+
+ org.eclipse
+ yasson
+ 1.0.6
+ test
+
diff --git a/implementation/src/test/java/io/smallrye/jwt/auth/cdi/ClaimConverterTest.java b/implementation/src/test/java/io/smallrye/jwt/auth/cdi/ClaimConverterTest.java
index c7321e87..ba6032f9 100644
--- a/implementation/src/test/java/io/smallrye/jwt/auth/cdi/ClaimConverterTest.java
+++ b/implementation/src/test/java/io/smallrye/jwt/auth/cdi/ClaimConverterTest.java
@@ -1,6 +1,7 @@
package io.smallrye.jwt.auth.cdi;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
import java.lang.annotation.Annotation;
import java.lang.reflect.Member;
@@ -22,6 +23,7 @@
import javax.enterprise.inject.spi.PassivationCapable;
import javax.enterprise.util.AnnotationLiteral;
import javax.inject.Inject;
+import javax.json.bind.JsonbBuilder;
import org.eclipse.microprofile.jwt.Claim;
import org.eclipse.microprofile.jwt.ClaimValue;
@@ -34,6 +36,7 @@
import org.junit.Test;
import io.smallrye.converters.SmallRyeConvertersBuilder;
+import io.smallrye.converters.api.Converter;
import io.smallrye.converters.api.Converters;
import io.smallrye.jwt.KeyUtils;
import io.smallrye.jwt.auth.principal.DefaultJWTCallerPrincipal;
@@ -61,6 +64,7 @@ public class ClaimConverterTest {
.addBeans(new ClaimInjectionBean<>(Double.class))
.addBeans(new ClaimInjectionBean<>(Boolean.class))
.addBeans(new ClaimInjectionBean<>(Character.class))
+ .addBeans(new ClaimInjectionBean<>(Address.class))
.inject(this)
.build();
@@ -89,6 +93,14 @@ public void convertRawWrapperTypes() {
assertEquals(true, raw.getBooleanClaim());
}
+ @Test
+ public void convertComplexType() {
+ final Address address = raw.getAddress();
+ assertNotNull(address);
+ assertEquals("street", address.getStreet());
+ assertEquals(1000, address.getCode().intValue());
+ }
+
@Produces
@RequestScoped
private static JsonWebToken jwt() throws Exception {
@@ -126,6 +138,9 @@ private static class RawConverterBean {
@Inject
@Claim("long")
private Long longClaim;
+ @Inject
+ @Claim("address")
+ private Address address;
String getName() {
return name;
@@ -158,6 +173,10 @@ public Boolean getBooleanClaim() {
public Long getLongClaim() {
return longClaim;
}
+
+ public Address getAddress() {
+ return address;
+ }
}
@RequestScoped
@@ -177,7 +196,11 @@ private static class ClaimInjectionBean implements Bean, PassivationCapabl
public ClaimInjectionBean(final Class klass) {
this.klass = klass;
- this.converters = new SmallRyeConvertersBuilder().build();
+ this.converters = new SmallRyeConvertersBuilder()
+ .withConverter(Address.class, 100,
+ // Jsonb does not support JsonObject to POJO conversion. You need to call toString on it.
+ (Converter) value -> JsonbBuilder.create().fromJson(value, Address.class))
+ .build();
}
@Override
@@ -321,4 +344,25 @@ public Claims standard() {
return INSTANCE.standard();
}
}
+
+ public static class Address {
+ private String street;
+ private Integer code;
+
+ public String getStreet() {
+ return street;
+ }
+
+ public void setStreet(final String street) {
+ this.street = street;
+ }
+
+ public Integer getCode() {
+ return code;
+ }
+
+ public void setCode(final Integer code) {
+ this.code = code;
+ }
+ }
}
diff --git a/implementation/src/test/resources/token-converter.json b/implementation/src/test/resources/token-converter.json
index 5ce5f4e6..d85975a0 100644
--- a/implementation/src/test/resources/token-converter.json
+++ b/implementation/src/test/resources/token-converter.json
@@ -16,5 +16,10 @@
"float": 99.9,
"double": 99.99,
"boolean": "true",
- "char": "y"
+ "char": "y",
+
+ "address": {
+ "street": "street",
+ "code": 1000
+ }
}