@Override
public JSONObject toJSONObject() {
JSONObject o = new JSONObject(customClaims);
if (iss != null) {
o.put(ISSUER_CLAIM, iss);
}
if (sub != null) {
o.put(SUBJECT_CLAIM, sub);
}
if (aud != null && ! aud.isEmpty()) {
if (aud.size() == 1) {
o.put(AUDIENCE_CLAIM, aud.get(0));
} else {
JSONArray audArray = new JSONArray();
audArray.addAll(aud);
o.put(AUDIENCE_CLAIM, audArray);
}
}
if (exp != null) {
o.put(EXPIRATION_TIME_CLAIM, exp.getTime() / 1000);
}
if (nbf != null) {
o.put(NOT_BEFORE_CLAIM, nbf.getTime() / 1000);
}
if (iat != null) {
o.put(ISSUED_AT_CLAIM, iat.getTime() / 1000);
}
if (jti != null) {
o.put(JWT_ID_CLAIM, jti);
}
if (typ != null) {
o.put(TYPE_CLAIM, typ);
}
return o;
}