You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
All 'out of the box' errors are Jackson ready and can be serialized as JSON, XML, and YAML. If you'd like to use GSON or something else, create a custom error creator.
japi-errors enables developers to craft custom error objects. To do so, implement the ApiErrorCreator interface, then pass an instance of your creator to ApiError.creator(myApiErrorCreator)
To see a working example, check out this source code
Example:
// Create an api error creatorpublicclassMyApiErrorCreatorimplementsIApiErrorCreator {
@OverridepublicApiErrorcreate(HttpStatusstatus, Stringmessage) {
returnnewMyApiError(message);
}
@OverridepublicApiErrorcreate(HttpStatusstatus, Throwablet) {
returnnewMyApiError(t.getMessage());
}
}
// Create a custom api error object// Add Json ignore properties (see source code link above)publicclassMyApiErrorextendsApiError {
@JsonPropertyprivateStringmessage;
MyApiError() {
super();
}
MyApiError(Stringmessage) {
this.message = message;
}
publicStringgetMessage() {
returnmessage;
}
}
Examples
Check out the following examples to see japi-errors in use: