1 package org.onap.vid.mso;
3 import com.fasterxml.jackson.annotation.JsonProperty;
4 import com.fasterxml.jackson.annotation.JsonPropertyOrder;
5 import com.fasterxml.jackson.core.JsonProcessingException;
6 import com.fasterxml.jackson.databind.ObjectMapper;
14 This is a brother of MsoResponseWrapper. I (Ittay) think it's better.
15 It is generic, immutable, and has some knowledge about RestObject.
16 The serialized "entity" field may be either String or nested object.
18 public class MsoResponseWrapper2<T> implements MsoResponseWrapperInterface {
20 final static ObjectMapper objectMapper = new ObjectMapper();
22 private final int status;
23 private final T entity;
24 private final String raw;
26 public MsoResponseWrapper2(RestObject<T> msoResponse) {
27 this.status = msoResponse.getStatusCode();
28 this.entity = msoResponse.get();
29 this.raw = msoResponse.getRaw();
32 public MsoResponseWrapper2(
33 @JsonProperty(value = "status", required = true) int status,
34 @JsonProperty(value = "entity", required = true) T entity) {
40 public int getStatus() {
45 @org.codehaus.jackson.annotate.JsonIgnore
46 @com.fasterxml.jackson.annotation.JsonIgnore
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;