From 09a85c3064da788c40becfde0d158cc945c2f9ef Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Wed, 21 Oct 2020 17:49:25 +0200 Subject: [PATCH] [Project] New added ResponseUtil.toResponse(I18nMessage) --- .../main/java/li/strolch/rest/helper/ResponseUtil.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/li.strolch.rest/src/main/java/li/strolch/rest/helper/ResponseUtil.java b/li.strolch.rest/src/main/java/li/strolch/rest/helper/ResponseUtil.java index e5fe58c0f..2f9941c6d 100644 --- a/li.strolch.rest/src/main/java/li/strolch/rest/helper/ResponseUtil.java +++ b/li.strolch.rest/src/main/java/li/strolch/rest/helper/ResponseUtil.java @@ -20,6 +20,7 @@ import li.strolch.privilege.base.PrivilegeException; import li.strolch.privilege.base.PrivilegeModelException; import li.strolch.service.JsonServiceResult; import li.strolch.service.api.ServiceResult; +import li.strolch.utils.I18nMessage; import li.strolch.utils.collections.Paging; import li.strolch.utils.helper.StringHelper; @@ -37,6 +38,15 @@ public class ResponseUtil { return Response.ok(json, MediaType.APPLICATION_JSON).build(); } + public static Response toResponse(I18nMessage msg) { + JsonObject response = new JsonObject(); + response.addProperty(MSG, msg.getMessage()); + + String json = new Gson().toJson(response); + + return Response.serverError().entity(json).type(MediaType.APPLICATION_JSON).build(); + } + public static Response toResponse(String errorMsg) { JsonObject response = new JsonObject(); response.addProperty(MSG, errorMsg);