Skip to content

Instantly share code, notes, and snippets.

@DenisZm
Created March 8, 2017 18:58
Show Gist options
  • Save DenisZm/2110d7001cb34c0d3028cde095c8c23a to your computer and use it in GitHub Desktop.
Save DenisZm/2110d7001cb34c0d3028cde095c8c23a to your computer and use it in GitHub Desktop.
package com.royalrangers.bean;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import java.io.Serializable;
public class ResultResponse implements Serializable {
private Object data = new EmptyJsonResponse();
private boolean success = false;
private ResultResponse() {
}
public Object getData() {
return data;
}
public boolean isSuccess() {
return success;
}
@JsonSerialize
public class EmptyJsonResponse { }
public static class ResponseMessage implements Serializable{
private String message;
ResponseMessage (String message) {
this.message = message;
}
public String getMessage() {
return message;
}
}
public static Builder newBuilder() {
return new ResultResponse().new Builder();
}
public class Builder {
private Builder() {
}
public Builder data(Object data) {
ResultResponse.this.data = data;
return this;
}
public Builder success() {
ResultResponse.this.success = true;
return this;
}
public Builder message(String message) {
ResultResponse.this.data = new ResponseMessage(message);
return this;
}
public ResultResponse build() {
return ResultResponse.this;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment