在JaxRs和Jersey中进行Rest调用时,客户端如何知道类的结构

时间:2016-11-02 18:36:38

标签: java web-services rest jersey jax-rs

我有一个带有以下参数的评论类

package com.rahul.restapi.messenger.model;

import java.util.Date;

import javax.xml.bind.annotation.XmlRootElement;

//added to test json response
@XmlRootElement
public class Comment {


    private long id;
    private String message;
    private Date created;
    private String author;

    public Comment() {

    }

    public Comment(long id, String message, String author) {
        this.id = id;
        this.message = message;
        this.author = author;
        this.created = new Date();
    }


    public long getId() {
        return id;
    }
    public void setId(long id) {
        this.id = id;
    }
    public String getMessage() {
        return message;
    }
    public void setMessage(String message) {
        this.message = message;
    }
    public Date getCreated() {
        return created;
    }
    public void setCreated(Date created) {
        this.created = created;
    }
    public String getAuthor() {
        return author;
    }
    public void setAuthor(String author) {
        this.author = author;
    }



}

并使用Rest Client By JaxRS我调用以下URL

http://localhost:8080/messenger/webapi/date/yesterday/messageJson

客户如何了解Comment Class的实现,以便以json格式正确获取响应?

提前致谢

1 个答案:

答案 0 :(得分:0)

您可以尝试以下内容。

   public <T> void someLongRunningMethod() {
         Service<T> service = //Code here to create your service or task
         service.addEventFilter(WorkerStateEvent.WORKER_STATE_SUCCEEDED, event -> toggleProgressIndicator(pi, false));
         service.addEventFilter(WorkerStateEvent.WORKER_STATE_FAILED, event -> toggleProgressIndicator(pi, false));
         service.addEventFilter(WorkerStateEvent.WORKER_STATE_CANCELLED, event -> toggleProgressIndicator(pi, false));
         service.addEventFilter(WorkerStateEvent.WORKER_STATE_RUNNING, event -> toggleProgressIndicator(pi, true));
         service.start();
    }

private void toggleProgressIndicator(ProgressIndicator pi, boolean start) {
    if(start){
        pi.toFront();
        pi.setVisible(true);
        pi.progressProperty().set(-1);
    }else {
        pi.toBack();
        pi.setVisible(false);
        pi.progressProperty().set(0);
    }
}