java-jwt
java-jwt copied to clipboard
Token content not sorted before serializing as JSON
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.
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