[Minor] Added constants for ServiceResult.toJson()
This commit is contained in:
parent
c862bc1a47
commit
5bfcc789b8
|
@ -15,6 +15,7 @@
|
||||||
*/
|
*/
|
||||||
package li.strolch.service.api;
|
package li.strolch.service.api;
|
||||||
|
|
||||||
|
import static li.strolch.model.Tags.Json.*;
|
||||||
import static li.strolch.utils.helper.ExceptionHelper.formatException;
|
import static li.strolch.utils.helper.ExceptionHelper.formatException;
|
||||||
import static li.strolch.utils.helper.ExceptionHelper.getExceptionMessageWithCauses;
|
import static li.strolch.utils.helper.ExceptionHelper.getExceptionMessageWithCauses;
|
||||||
import static li.strolch.utils.helper.StringHelper.isEmpty;
|
import static li.strolch.utils.helper.StringHelper.isEmpty;
|
||||||
|
@ -24,6 +25,7 @@ import java.util.ResourceBundle;
|
||||||
|
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import li.strolch.exception.StrolchUserMessageException;
|
import li.strolch.exception.StrolchUserMessageException;
|
||||||
|
import li.strolch.model.Tags;
|
||||||
import li.strolch.model.i18n.I18nMessageToJsonVisitor;
|
import li.strolch.model.i18n.I18nMessageToJsonVisitor;
|
||||||
import li.strolch.utils.I18nMessage;
|
import li.strolch.utils.I18nMessage;
|
||||||
|
|
||||||
|
@ -220,20 +222,20 @@ public class ServiceResult {
|
||||||
public JsonObject toJson() {
|
public JsonObject toJson() {
|
||||||
JsonObject json = new JsonObject();
|
JsonObject json = new JsonObject();
|
||||||
|
|
||||||
json.addProperty("state", this.state.name());
|
json.addProperty(Tags.Json.STATE, this.state.name());
|
||||||
json.addProperty("msg", isEmpty(this.message) ? "-" : this.message);
|
json.addProperty(MSG, isEmpty(this.message) ? "-" : this.message);
|
||||||
|
|
||||||
if (this.throwable != null) {
|
if (this.throwable != null) {
|
||||||
json.addProperty("exceptionMsg", getExceptionMessageWithCauses(this.throwable, false));
|
json.addProperty(EXCEPTION_MSG, getExceptionMessageWithCauses(this.throwable, false));
|
||||||
json.addProperty("throwable", formatException(this.throwable));
|
json.addProperty(THROWABLE, formatException(this.throwable));
|
||||||
|
|
||||||
if (this.throwable instanceof StrolchUserMessageException
|
if (this.throwable instanceof StrolchUserMessageException
|
||||||
&& ((StrolchUserMessageException) this.throwable).hasI18n())
|
&& ((StrolchUserMessageException) this.throwable).hasI18n())
|
||||||
json.add("i18n", ((StrolchUserMessageException) this.throwable).getI18n()
|
json.add(I_18_N, ((StrolchUserMessageException) this.throwable).getI18n()
|
||||||
.accept(new I18nMessageToJsonVisitor()));
|
.accept(new I18nMessageToJsonVisitor()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!json.has("i18n") && this.i18nMessage != null)
|
if (!json.has(I_18_N) && this.i18nMessage != null)
|
||||||
json.add("i18n", this.i18nMessage.accept(new I18nMessageToJsonVisitor()));
|
json.add("i18n", this.i18nMessage.accept(new I18nMessageToJsonVisitor()));
|
||||||
|
|
||||||
return json;
|
return json;
|
||||||
|
|
|
@ -143,6 +143,10 @@ public class Tags {
|
||||||
|
|
||||||
// miscellaneous
|
// miscellaneous
|
||||||
|
|
||||||
|
public static final String MSG = "msg";
|
||||||
|
public static final String EXCEPTION_MSG = "exceptionMsg";
|
||||||
|
public static final String THROWABLE = "throwable";
|
||||||
|
public static final String I_18_N = "i18n";
|
||||||
public static final String MSG_TYPE = "msgType";
|
public static final String MSG_TYPE = "msgType";
|
||||||
public static final String USERNAME = "username";
|
public static final String USERNAME = "username";
|
||||||
public static final String PASSWORD = "password";
|
public static final String PASSWORD = "password";
|
||||||
|
|
Loading…
Reference in New Issue