1 package org.onap.vid.model.mso;
3 import com.fasterxml.jackson.annotation.JsonIgnore;
4 import com.fasterxml.jackson.annotation.JsonProperty;
5 import com.fasterxml.jackson.annotation.JsonPropertyOrder;
6 import com.fasterxml.jackson.core.JsonProcessingException;
7 import com.fasterxml.jackson.databind.ObjectMapper;
15 This is a brother of MsoResponseWrapper. I (Ittay) think it's better.
16 It is generic, immutable, and has some knowledge about RestObject.
17 The serialized "entity" field may be either String or nested object.
19 public class MsoResponseWrapper2<T> implements MsoResponseWrapperInterface {
21 final static ObjectMapper objectMapper = new ObjectMapper();
23 private final int status;
24 private final T entity;
25 private final String raw;
27 public MsoResponseWrapper2(RestObject<T> msoResponse) {
28 this.status = msoResponse.getStatusCode();
29 this.entity = msoResponse.get();
30 this.raw = msoResponse.getRaw();
33 public MsoResponseWrapper2(
34 @JsonProperty(value = "status", required = true) int status,
35 @JsonProperty(value = "entity", required = true) T entity) {
41 public int getStatus() {
47 public String getResponse() {
49 return objectMapper.writeValueAsString(this);
50 } catch (JsonProcessingException e) {
51 return getEntity() != null ? getEntity().toString() : null;
56 public Object getEntity() {
57 return entity != null ? entity : raw;