All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.flowthings.client.response.Response Maven / Gradle / Ivy

There is a newer version: 0.9.3.2
Show newest version
package com.flowthings.client.response;

import java.util.List;

import com.flowthings.client.Serializer;

public class Response {
  protected Head head;
  protected T body;

  public Head getHead() {
    return head;
  }

  public void setHead(Head head) {
    this.head = head;
  }

  public T get() {
    if (!head.isOk()) {
      throw new IllegalStateException("Cannot get the body of an error response");
    }
    return body;
  }

  public void setBody(T t) {
    body = t;
  }

  public T getBody() {
    return get();
  }

  public String json() {
    return Serializer.toJson(this);
  }

  @Override
  public String toString() {
    return "FlowResponse [head=" + head + ", body=" + body + "]";
  }

  public static class Head {
    private boolean ok;
    private List messages;
    private List errors;
    private int status;
    private String msgId;

    public boolean isOk() {
      return ok;
    }

    public void setOk(boolean ok) {
      this.ok = ok;
    }

    public List getMessages() {
      return messages;
    }

    public void setMessages(List messages) {
      this.messages = messages;
    }

    public List getErrors() {
      return errors;
    }

    public void setErrors(List errors) {
      this.errors = errors;
    }

    public int getStatus() {
      return status;
    }

    public void setStatus(int status) {
      this.status = status;
    }

    public String getMsgId() {
      return msgId;
    }

    public void setMsgId(String msgId) {
      this.msgId = msgId;
    }

    @Override
    public String toString() {
      return "Head [ok=" + ok + ", messages=" + messages + ", errors=" + errors + ", status=" + status + "]";
    }

  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy