From e6f7a4b02703ca6ecb3131ceefb2cdbe7de3dbab Mon Sep 17 00:00:00 2001 From: Lubos Racansky Date: Mon, 23 Oct 2023 10:14:35 +0200 Subject: [PATCH] Fix #220: ToString and Equals for ObjectResponse and ObjectRequest --- .../core/rest/model/base/entity/Error.java | 4 +++ .../model/base/request/ObjectRequest.java | 4 +++ .../model/base/response/ObjectResponse.java | 28 +++++-------------- .../rest/model/base/response/Response.java | 6 +++- 4 files changed, 20 insertions(+), 22 deletions(-) diff --git a/rest-model-base/src/main/java/io/getlime/core/rest/model/base/entity/Error.java b/rest-model-base/src/main/java/io/getlime/core/rest/model/base/entity/Error.java index 236ed6d..b58df89 100644 --- a/rest-model-base/src/main/java/io/getlime/core/rest/model/base/entity/Error.java +++ b/rest-model-base/src/main/java/io/getlime/core/rest/model/base/entity/Error.java @@ -17,12 +17,16 @@ import jakarta.validation.constraints.NotBlank; +import lombok.EqualsAndHashCode; +import lombok.ToString; /** * Transport object for RESTful API representing an error instance. * * @author Petr Dvorak, petr@wultra.com */ +@ToString +@EqualsAndHashCode public class Error { /** diff --git a/rest-model-base/src/main/java/io/getlime/core/rest/model/base/request/ObjectRequest.java b/rest-model-base/src/main/java/io/getlime/core/rest/model/base/request/ObjectRequest.java index f0eacab..7b9425c 100644 --- a/rest-model-base/src/main/java/io/getlime/core/rest/model/base/request/ObjectRequest.java +++ b/rest-model-base/src/main/java/io/getlime/core/rest/model/base/request/ObjectRequest.java @@ -18,6 +18,8 @@ import jakarta.validation.Valid; import jakarta.validation.constraints.NotNull; +import lombok.EqualsAndHashCode; +import lombok.ToString; /** * Simple class representing a request with an object. @@ -26,6 +28,8 @@ * * @param Type of the request object. */ +@ToString +@EqualsAndHashCode public class ObjectRequest { @Valid diff --git a/rest-model-base/src/main/java/io/getlime/core/rest/model/base/response/ObjectResponse.java b/rest-model-base/src/main/java/io/getlime/core/rest/model/base/response/ObjectResponse.java index 6ac663e..77196a4 100644 --- a/rest-model-base/src/main/java/io/getlime/core/rest/model/base/response/ObjectResponse.java +++ b/rest-model-base/src/main/java/io/getlime/core/rest/model/base/response/ObjectResponse.java @@ -18,6 +18,8 @@ import jakarta.validation.Valid; import jakarta.validation.constraints.NotNull; +import lombok.EqualsAndHashCode; +import lombok.ToString; /** * Generic response with status and object of a custom class. @@ -26,6 +28,8 @@ * * @param Type of the response object */ +@ToString(callSuper = true) +@EqualsAndHashCode(callSuper = true) public class ObjectResponse extends Response { @Valid @@ -36,7 +40,7 @@ public class ObjectResponse extends Response { * Default constructor */ public ObjectResponse() { - this.status = Status.OK; + super(Status.OK); } /** @@ -45,7 +49,7 @@ public ObjectResponse() { * @param responseObject Response object. */ public ObjectResponse(T responseObject) { - this.status = Status.OK; + super(Status.OK); this.responseObject = responseObject; } @@ -56,28 +60,10 @@ public ObjectResponse(T responseObject) { * @param responseObject Response object. */ public ObjectResponse(String status, T responseObject) { - this.status = status; + super(status); this.responseObject = responseObject; } - /** - * Get response status. - * - * @return Response status. - */ - public String getStatus() { - return status; - } - - /** - * Set response status. - * - * @param status Response status. - */ - public void setStatus(String status) { - this.status = status; - } - /** * Get response object. * diff --git a/rest-model-base/src/main/java/io/getlime/core/rest/model/base/response/Response.java b/rest-model-base/src/main/java/io/getlime/core/rest/model/base/response/Response.java index 2eb09a9..32bfab1 100644 --- a/rest-model-base/src/main/java/io/getlime/core/rest/model/base/response/Response.java +++ b/rest-model-base/src/main/java/io/getlime/core/rest/model/base/response/Response.java @@ -17,12 +17,16 @@ import jakarta.validation.constraints.NotBlank; +import lombok.EqualsAndHashCode; +import lombok.ToString; /** * Simple status only response object. * * @author Petr Dvorak, petr@wultra.com */ +@EqualsAndHashCode +@ToString public class Response { /** @@ -46,7 +50,7 @@ public static class Status { * Response status. */ @NotBlank - protected String status; + private String status; /** * Default constructor.