Jira-Rest-Java-Api:在转换为JSCON时,如何在没有二阶段方法的情况下参考POJO变量

发布于 2025-01-25 20:59:51 字数 1996 浏览 0 评论 0原文

JIRA JQL搜索查询:带终点的帖子方法http:// localhost:8080/rest/api/2/

body:
{
    "jql":"project = QA and key=123",
    "startAt":0,
    "maxResults":1,
    "fields":[
        "id",
        "key",
        "custom_Field1"
        ]
}

上面的结构搜索结构为postman exudy的字段数组的预期值提供了预期值

: < < /em>

REST API JAVA实现

为上述结构POJO类定义,并且在POJO类创建JSCON时,POJO类的变量被忽略了,因为它们不是通过setter方法设置的。因此,从响应中无法获得所需的输出。如何根据上述结构将POJO类转换为JSCON。

从POJO类转换为JSCON

{
 "jql":"project = QA and key=123",
 "startAt":0,
 "maxResults":1,
 "fields":[]
}

使用此结构,它在Java Rest rest API POJO类中的custom_field1返回了

如下

public root{
    private String jql;
    private int startAt;
    private int maxResults;
    private List<field> fields;
    
    public void setjql(String jql){
        this.jql=jql;
    }
    public String getjql(){
        return this.jql;
    }
    public void setstartAt(int startAt){
        this.startAt=startAt;
    }
    public int getstartAt(){
        return this.startAt;
    }
    public void setmaxResults(int maxResults){
        this.maxResults=maxResults;
    }
    public int getmaxResults(){
        return this.maxResults;
    }
    public void setfields(List<field> fields){
        this.fields=fields;
    }
    public List<fields> getfileds(){
        return this.fields;
    }
} 

public field{   
    private int id;
    private String key;
    private String custom_Field1;
    
    public void setID(int id){
        this.id=id;
    }
    public int getID(){
        return this.id;
    }
    public void setKey(String key){
        this.key=key;
    }
    public String getKey(){
        return this.key;
    }
    public void setcustom_Field1(String custom_Field1){
        this.custom_Field1=custom_Field1;
    }
    public String getcustom_Field1(){
        return this.custom_Field1;
    }

    
}

JIRA JQL Search Query: post method with end point http://localhost:8080/rest/api/2/search

body:
{
    "jql":"project = QA and key=123",
    "startAt":0,
    "maxResults":1,
    "fields":[
        "id",
        "key",
        "custom_Field1"
        ]
}

above structure giving expected values for variables from fields array in postman

ISSUE :

REST API JAVA IMPLEMENTATION

For above structure POJO class been defined and while creating JSCON from POJO Class, variables from fields POJO class are ignored as they are not set by setter method. Due to this not getting desired output from response. How to convert POJO class to JSCON as per above structure.

Converted JSCON from POJO CLASS

{
 "jql":"project = QA and key=123",
 "startAt":0,
 "maxResults":1,
 "fields":[]
}

with this structure it is not returning value for custom_Field1

in Java Rest API POJO Class created as below

public root{
    private String jql;
    private int startAt;
    private int maxResults;
    private List<field> fields;
    
    public void setjql(String jql){
        this.jql=jql;
    }
    public String getjql(){
        return this.jql;
    }
    public void setstartAt(int startAt){
        this.startAt=startAt;
    }
    public int getstartAt(){
        return this.startAt;
    }
    public void setmaxResults(int maxResults){
        this.maxResults=maxResults;
    }
    public int getmaxResults(){
        return this.maxResults;
    }
    public void setfields(List<field> fields){
        this.fields=fields;
    }
    public List<fields> getfileds(){
        return this.fields;
    }
} 

public field{   
    private int id;
    private String key;
    private String custom_Field1;
    
    public void setID(int id){
        this.id=id;
    }
    public int getID(){
        return this.id;
    }
    public void setKey(String key){
        this.key=key;
    }
    public String getKey(){
        return this.key;
    }
    public void setcustom_Field1(String custom_Field1){
        this.custom_Field1=custom_Field1;
    }
    public String getcustom_Field1(){
        return this.custom_Field1;
    }

    
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文