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

cn.hyperchain.sdk.response.mq.MQResponse Maven / Gradle / Ivy

There is a newer version: 1.4.3
Show newest version
package cn.hyperchain.sdk.response.mq;

import cn.hyperchain.sdk.response.Response;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.annotations.Expose;

import java.util.ArrayList;
import java.util.List;

public class MQResponse extends Response {
    @Expose
    private JsonElement result;
    private static final Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();

    /**
     * return list of queue names.
     *
     * @return list of queue names
     */
    public List getQueueNames() {
        List queue = new ArrayList<>();
        if (result.isJsonArray()) {
            JsonArray jsonArray = result.getAsJsonArray();
            for (JsonElement element : jsonArray) {
                String name = gson.fromJson(element, String.class);
                queue.add(name);
            }
        }

        return queue;
    }

    public String getExchanger() {
        return result.getAsString();
    }

    @Override
    public String toString() {
        return "MQResponse{" +
                "jsonrpc='" + jsonrpc + '\'' +
                ", id='" + id + '\'' +
                ", code=" + code +
                ", message='" + message + '\'' +
                ", namespace='" + namespace + '\'' +
                ", result" + result + '\'' +
                '}';
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy