Skip to content

java.lang.NoSuchMethodError: org.json.JSONTokener.<init>(Ljava/io/Reader;)V #882

@ejoseca

Description

@ejoseca

Description
JWS cannot be deserialized in Android devices.

Steps to reproduce

  1. Add the required dependencies for an Android project as shown in the README.md
dependencies {
    api('io.jsonwebtoken:jjwt-api:0.12.3')
    runtimeOnly('io.jsonwebtoken:jjwt-impl:0.12.3') 
    runtimeOnly('io.jsonwebtoken:jjwt-orgjson:0.12.3') {
        exclude(group: 'org.json', module: 'json') //provided by Android natively
    }
}
  1. Create a parser
Jwts.parser()
  .verifyWith(publicKey)
  .build()
  .parseSignedClaims(jwsString);
  1. Try to deserialize a signed JWT in an Android device
  2. An error is thrown: java.lang.NoSuchMethodError: org.json.JSONTokener.<init>(Ljava/io/Reader;)V

Cause
Since 0.12.0, the class io.jsonwebtoken.orgjson.io.OrgJsonDeserializer, in its parse() method, is trying to create a JSONTokener passing a Reader as argument to the constructor.
This constructor is not available in the Android implementation of JSONTokener: https://android.googlesource.com/platform/libcore/+/refs/heads/main/json/src/main/java/org/json/JSONTokener.java

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions