-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace gson with Android's org.json.*
- Loading branch information
Showing
11 changed files
with
377 additions
and
407 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
99 changes: 99 additions & 0 deletions
99
lib/src/main/java/com/auth0/android/jwt/JSONObjectClaim.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package com.auth0.android.jwt; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
|
||
import org.json.JSONArray; | ||
import org.json.JSONException; | ||
import org.json.JSONObject; | ||
|
||
import java.util.Date; | ||
|
||
final class JSONObjectClaim implements Claim { | ||
@NonNull | ||
private final String name; | ||
@NonNull | ||
private final JSONObject object; | ||
|
||
JSONObjectClaim(@NonNull JSONObject object, @NonNull String name) { | ||
this.object = object; | ||
this.name = name; | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public Boolean asBoolean() { | ||
try { | ||
return object.getBoolean(name); | ||
} catch (JSONException exception) { | ||
return null; | ||
} | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public Integer asInt() { | ||
try { | ||
return object.getInt(name); | ||
} catch (JSONException exception) { | ||
return null; | ||
} | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public Long asLong() { | ||
try { | ||
return object.getLong(name); | ||
} catch (JSONException exception) { | ||
return null; | ||
} | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public Double asDouble() { | ||
try { | ||
return object.getDouble(name); | ||
} catch (JSONException exception) { | ||
return null; | ||
} | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public String asString() { | ||
if (object.isNull(name) || object.optJSONArray(name) != null || object.optJSONObject(name) != null) { | ||
return null; | ||
} | ||
|
||
try { | ||
return object.getString(name); | ||
} catch (JSONException exception) { | ||
return null; | ||
} | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public Date asDate() { | ||
final Long value = asLong(); | ||
if (value != null) { | ||
return new Date(value * 1000); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public JSONArray asArray() { | ||
return object.optJSONArray(name); | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public JSONObject asObject() { | ||
return object.optJSONObject(name); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.