package eu.mikroskeem.utils.simplerpc; import com.google.gson.Gson; import com.google.gson.JsonSyntaxException; import lombok.Data; import lombok.ToString; import org.jetbrains.annotations.Nullable; import java.io.*; import java.util.List; /** * RPCResponse class */ @Data @ToString public class RPCResponse implements Serializable { private String id; private Status status; private String message; private List response; @Nullable public byte[] toByteArray() { try { return new Gson().toJson(this, RPCResponse.class).getBytes("UTF-8"); } catch (JsonSyntaxException |UnsupportedEncodingException e){ e.printStackTrace(); } return null; } @Nullable public static RPCResponse fromByteArray(byte[] serialized){ try { return new Gson().fromJson(new String(serialized, "UTF-8"), RPCResponse.class); } catch (JsonSyntaxException|UnsupportedEncodingException e){ e.printStackTrace(); } return null; } public enum Status { SUCCESS, ERROR } }