@@ -133,6 +133,7 @@ public void setId(String id) {
133133 this .jsonLdObject .put (JSONLD_TERM_ID , id );
134134 }
135135
136+ @ SuppressWarnings ("unchecked" )
136137 public String getCredentialSubject () {
137138
138139 Object object = this .getJsonLdCredentialSubject ().get (JSONLD_TERM_ID );
@@ -141,6 +142,14 @@ public String getCredentialSubject() {
141142 if (object instanceof URI ) return ((URI ) object ).toString ();
142143 if (object instanceof String ) return (String ) object ;
143144
145+ if (object instanceof LinkedHashMap ) {
146+
147+ Object id = ((LinkedHashMap <String , Object >) object ).get (JSONLD_TERM_ID );
148+
149+ if (id instanceof URI ) return ((URI ) id ).toString ();
150+ if (id instanceof String ) return (String ) id ;
151+ }
152+
144153 throw new IllegalStateException ("Invalid object for '" + JSONLD_TERM_ID + "': " + object );
145154 }
146155
@@ -186,12 +195,24 @@ public void setType(List<String> type) {
186195 this .jsonLdObject .put (JSONLD_TERM_TYPE , type );
187196 }
188197
198+ @ SuppressWarnings ("unchecked" )
189199 public String getIssuer () {
190200
191201 Object object = this .jsonLdObject .get (JSONLD_TERM_ISSUER );
202+ if (object == null ) return null ;
203+
192204 if (object instanceof URI ) return ((URI ) object ).toString ();
193205 if (object instanceof String ) return (String ) object ;
194- return null ;
206+
207+ if (object instanceof LinkedHashMap ) {
208+
209+ Object id = ((LinkedHashMap <String , Object >) object ).get (JSONLD_TERM_ID );
210+
211+ if (id instanceof URI ) return ((URI ) id ).toString ();
212+ if (id instanceof String ) return (String ) id ;
213+ }
214+
215+ throw new IllegalStateException ("Invalid object for '" + JSONLD_TERM_ISSUER + "': " + object );
195216 }
196217
197218 public void setIssuer (String issuer ) {
@@ -206,6 +227,7 @@ public Date getIssuanceDate() {
206227
207228 String issuanceDateString = (String ) this .jsonLdObject .get (JSONLD_TERM_ISSUANCE_DATE );
208229 if (issuanceDateString == null ) return null ;
230+
209231 try {
210232 return DATE_FORMAT .parse (issuanceDateString );
211233 } catch (ParseException ex ) {
@@ -229,6 +251,7 @@ public Date getExpirationDate() {
229251
230252 String expirationDateString = (String ) this .jsonLdObject .get (JSONLD_TERM_EXPIRATION_DATE );
231253 if (expirationDateString == null ) return null ;
254+
232255 try {
233256 return DATE_FORMAT .parse (expirationDateString );
234257 } catch (ParseException ex ) {
@@ -291,12 +314,15 @@ private static void validateRun(Runnable runnable, String message) throws Illega
291314
292315 public void validate () throws IllegalStateException {
293316
317+ validateRun (() -> { validateTrue (this .getJsonLdObject () != null ); }, "Missing verifiable credential." );
318+ validateRun (() -> { validateTrue (this .getJsonLdCredentialSubject () != null ); }, "Missing 'credentialSubject'." );
319+
294320 validateRun (() -> { validateTrue (this .getContext ().size () > 0 ); }, "Bad or missing '@context'." );
295321 validateRun (() -> { validateTrue (this .getType ().size () > 0 ); }, "Bad or missing '@type'." );
296322 validateRun (() -> { validateTrue (this .getIssuer () != null ); }, "Bad or missing 'issuer'." );
297323 validateRun (() -> { validateTrue (this .getIssuanceDate () != null ); }, "Bad or missing 'issuanceDate'." );
298324 validateRun (() -> { this .getExpirationDate (); }, "Bad 'expirationDate'." );
299- validateRun (() -> { this .getCredentialSubject (); }, "Bad or missing 'credentialSubject'." );
325+ validateRun (() -> { this .getCredentialSubject (); }, "Bad 'credentialSubject'." );
300326
301327 validateRun (() -> { if (this .getId () != null ) validateUrl (this .getId ()); }, "'@id' must be a valid URI." );
302328 validateRun (() -> { validateUrl (this .getIssuer ()); }, "'issuer' must be a valid URI." );
0 commit comments