Package general.common
Class ApiEnvelope
- java.lang.Object
-
- general.common.ApiEnvelope
-
public class ApiEnvelope extends java.lang.ObjectEnvelope/wrapper for API responses. This class standardizes the JSON shape returned by the API by always including theapiVersionand optionally including either a successful payload (message/data) or an error description (error). It is typically created via one of the staticwrap(...)factory methods. UseasJsonNode()to obtain aJsonNoderepresentation of the envelope, orasJsValue()to obtain a PlayJsValue. Note: An instance is intended to represent either a success response or an error response. If anApiEnvelope.ErrorCodeis present, the envelope is treated as an error regardless of any provided data.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classApiEnvelope.ErrorCode
-
Constructor Summary
Constructors Constructor Description ApiEnvelope()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description com.fasterxml.jackson.databind.JsonNodeasJsonNode()play.api.libs.json.JsValueasJsValue()static ApiEnvelopewrap(com.fasterxml.jackson.databind.JsonNode data)static ApiEnvelopewrap(java.lang.Object obj)static ApiEnvelopewrap(java.lang.String message)static ApiEnvelopewrap(java.lang.String message, com.fasterxml.jackson.databind.JsonNode data)static ApiEnvelopewrap(java.lang.String message, ApiEnvelope.ErrorCode errorCode)
-
-
-
Method Detail
-
wrap
public static ApiEnvelope wrap(java.lang.Object obj)
-
wrap
public static ApiEnvelope wrap(com.fasterxml.jackson.databind.JsonNode data)
-
wrap
public static ApiEnvelope wrap(java.lang.String message)
-
wrap
public static ApiEnvelope wrap(java.lang.String message, com.fasterxml.jackson.databind.JsonNode data)
-
wrap
public static ApiEnvelope wrap(java.lang.String message, ApiEnvelope.ErrorCode errorCode)
-
asJsonNode
public com.fasterxml.jackson.databind.JsonNode asJsonNode()
-
asJsValue
public play.api.libs.json.JsValue asJsValue()
-
-