-
Notifications
You must be signed in to change notification settings - Fork 948
PublicClaims.AUDIENCE (aud) expected to be String or "Array of Strings", not Collection(aka List) by PayloadSerializer #508
Copy link
Copy link
Closed
Labels
bugThis points to a verified bug in the codeThis points to a verified bug in the code
Description
Describe the problem
By default jackson deserializes to ArrayList. Can not find an easy way to change this behavior.
so, having payload = {exp=1630398915, aud=["firma_x","firma_y"]} following code
Map payloadMap = new ObjectMapper().readValue(payload, Map.class);
String result = JWT.create()
.withPayload(payloadMap)
.sign(Algorithm.HMAC256("secret"));
will cause an exception:
Caused by: java.lang.ClassCastException: class java.util.ArrayList cannot be cast to class [Ljava.lang.String; (java.util.ArrayList and [Ljava.lang.String; are in module java.base of loader 'bootstrap')
at com.auth0.jwt.impl.PayloadSerializer.serialize(PayloadSerializer.java:40)
at com.auth0.jwt.impl.PayloadSerializer.serialize(PayloadSerializer.java:18)
at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider._serialize(DefaultSerializerProvider.java:480)
Not sure, why special handling for PublicClaims.AUDIENCE is needed in first place, but it could be much more convenient to support collections as well.
Note: no errors in other places(Claims) where collections are used.
What was the expected behavior?
Collections can be handelt as well.
Environment
- Version of this library used: 3.18.1
- Version of Java used: jdk-14.0.2
- Other modules/plugins/libraries that might be involved: com.fasterxml.jackson.core:jackson-databind:2.12.4
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugThis points to a verified bug in the codeThis points to a verified bug in the code