Skip to content

Commit cb0adca

Browse files
committed
Better toString() method and better error messages.
Signed-off-by: Markus Sabadello <[email protected]>
1 parent 2b8f57c commit cb0adca

File tree

1 file changed

+9
-27
lines changed

1 file changed

+9
-27
lines changed

src/main/java/com/danubetech/verifiablecredentials/VerifiableCredential.java

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -314,8 +314,8 @@ private static void validateRun(Runnable runnable, String message) throws Illega
314314

315315
public void validate() throws IllegalStateException {
316316

317-
validateRun(() -> { validateTrue(this.getJsonLdObject() != null); }, "Missing verifiable credential.");
318-
validateRun(() -> { validateTrue(this.getJsonLdCredentialSubject() != null); }, "Missing 'credentialSubject'.");
317+
validateRun(() -> { validateTrue(this.getJsonLdObject() != null); }, "Bad or missing verifiable credential.");
318+
validateRun(() -> { validateTrue(this.getJsonLdCredentialSubject() != null); }, "Bad or missing 'credentialSubject'.");
319319

320320
validateRun(() -> { validateTrue(this.getContext().size() > 0); }, "Bad or missing '@context'.");
321321
validateRun(() -> { validateTrue(this.getType().size() > 0); }, "Bad or missing '@type'.");
@@ -336,32 +336,14 @@ public void validate() throws IllegalStateException {
336336
*/
337337

338338
@Override
339-
public int hashCode() {
340-
final int prime = 31;
341-
int result = 1;
342-
result = prime * result + ((jsonLdObject == null) ? 0 : jsonLdObject.hashCode());
343-
return result;
344-
}
339+
public String toString() {
345340

346-
@Override
347-
public boolean equals(Object obj) {
348-
if (this == obj)
349-
return true;
350-
if (obj == null)
351-
return false;
352-
if (getClass() != obj.getClass())
353-
return false;
354-
VerifiableCredential other = (VerifiableCredential) obj;
355-
if (jsonLdObject == null) {
356-
if (other.jsonLdObject != null)
357-
return false;
358-
} else if (!jsonLdObject.equals(other.jsonLdObject))
359-
return false;
360-
return true;
361-
}
341+
try {
362342

363-
@Override
364-
public String toString() {
365-
return "VerifiableCredential [jsonLdObject=" + jsonLdObject + "]";
343+
return this.toJsonString();
344+
} catch (IOException ex) {
345+
346+
return super.toString();
347+
}
366348
}
367349
}

0 commit comments

Comments
 (0)