package com.hssx.pcbms.util;

import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.annotation.JsonInclude;

import java.io.Serializable;

public class HttpRespMsg implements Serializable {

    //status code, ok or error.
    public String code;


    @JsonInclude(JsonInclude.Include.NON_NULL)
    public String msg;

    //data content, in jsonformat, or zipped string when format is gzip
    @JsonInclude(JsonInclude.Include.NON_NULL)
    public Object data;

    public HttpRespMsg() {
        code = "ok";
    }

    public void setError(String errorMsg) {
        code = "error";
        msg = errorMsg;
    }


    public String toJSONStr() {
        JSONObject json = new JSONObject();
        json.put("code", code);
        json.put("data", data);
        json.put("msg", msg);

        return json.toJSONString();
    }
}
