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

ca.bitcoco.jsk.message.MessageResponseBody Maven / Gradle / Ivy

package ca.bitcoco.jsk.message;

/**
 * Core message rpc request coreResponse format
 * Used as message rpc request response
 * @author Jiangqi Li
 */
public class MessageResponseBody {


    private T result;
    private String message;
    private RPCError error;

    public MessageResponseBody() {

    }

    /**
     * Create an responseBody used in ResponseEntity.
     *
     * @param result  coreResponse result.
     * @param message coreResponse message.
     * @param exception   Exception.
     * @param debugMessage String debugMessage.
     * @param errorCode    int errorCode.
     */
    private MessageResponseBody(T result, String message, Exception exception, String debugMessage, int errorCode) {
        this.result = result;
        this.message = message;
        if (exception != null) {
            this.error = new RPCError(exception, debugMessage, errorCode);
        }
    }

//    public static  MappingJacksonValue result2(@Nullable T result) {
//        MappingJacksonValue mapper = new MappingJacksonValue(new ResponseBody(result, null, null, null));
//        SimpleFilterProvider simpleFilterProvider = new SimpleFilterProvider().setFailOnUnknownId(false);
//        // simpleFilterProvider.addFilter("oneFilter", SimpleBeanPropertyFilter.filterOutAllExcept("id","address"));
//        mapper.setFilters(simpleFilterProvider);
//        return mapper;
//    }


    public static  MessageResponseBody result(T result) {
        return new MessageResponseBody(result, null, null, null, 10000);
    }

    public static  MessageResponseBody result(T result, String message) {
        return new MessageResponseBody(result, message, null, null, 10000);
    }


    public static  MessageResponseBody error(Exception error) {
        return new MessageResponseBody(null, null, error, null, 10000);
    }

    public static  MessageResponseBody error(Exception error, String message) {
        return new MessageResponseBody(null, message, error, null, 10000);
    }


    public static  MessageResponseBody error(Exception error, String message, String debugMessage) {
        return new MessageResponseBody(null, message, error, debugMessage, 10000);
    }

    public static  MessageResponseBody error(Exception error, String message, int errorCode) {
        return new MessageResponseBody(null, message, error, null, errorCode);
    }

    public static  MessageResponseBody error(Exception error, String message, String debugMessage, int errorCode) {
        return new MessageResponseBody(null, message, error, debugMessage, errorCode);
    }


    public String getMessage() {
        return message;
    }


    public RPCError getError() {
        return error;
    }

    public T getResult() {
        return result;
    }


    public MessageResponseBody setResult(T result) {
        this.result = result;
        return this;
    }


    public MessageResponseBody setMessage(String message) {
        this.message = message;
        return this;
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy