java-jwt icon indicating copy to clipboard operation
java-jwt copied to clipboard

Token content not sorted before serializing as JSON

Open rhelgeby opened this issue 8 years ago • 1 comments

The constructor of JWTCreator uses MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, but according to the docs, it doesn't sort maps. Then writing tests that signs a token and compares against a hard coded string will be unpredictable.

I've worked around this issue in tests by decoding it and then comparing content.

rhelgeby avatar Dec 11 '17 10:12 rhelgeby

The only order guaranteed to be preserved is the order of JSON arrays. Tests should not depend on the order of the JSON properties. I'm using a custom matcher to check the properties on this library's tests -> https://github.com/auth0/java-jwt/blob/master/lib/src/test/java/com/auth0/jwt/JsonMatcher.java

lbalmaceda avatar Dec 26 '17 17:12 lbalmaceda