Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Jira API自动化-放心_Java_Json_Rest_Jira Rest Api - Fatal编程技术网

Java Jira API自动化-放心

Java Jira API自动化-放心,java,json,rest,jira-rest-api,Java,Json,Rest,Jira Rest Api,我试图通过RESTAPI和Java REST Assured自动化Jira问题创建。下面是我的代码片段 我需要用Java重新构造以下JSON并将其传递给正文 { "fields": { "project": { "id": "13204" }, "summary": "welcome to testing1", "issuetype": { "id": "3" }, "reporter": { "na

我试图通过RESTAPI和Java REST Assured自动化Jira问题创建。下面是我的代码片段

我需要用Java重新构造以下JSON并将其传递给正文

{
"fields": {
    "project": {
        "id": "13204"
    },
    "summary": "welcome to testing1",
    "issuetype": {
        "id": "3"
    },
    "reporter": {
        "name": "parthiban.selvaraj"
    },
    "priority": {
        "id": "3"
    },
    "description": "description",
     "customfield_10201": {
       "id": "10608"
    }
}
}

下面是我使用getter和setter的Java代码:

包装jira;
导入com.google.gson.gson;
导入io.restassured.restassured;
导入io.restassured.authentication.PreemptiveBasicAuthScheme;
导入io.restassured.http.ContentType;
导入io.restasured.http.Method;
导入io.restassured.path.json.JsonPath;
导入io.restassured.response.response;
导入io.restassured.specification.RequestSpecification;
导入java.util.List;
公屋{
公共静态void main(字符串参数[]){
System.out.println(“欢迎”);
RestAssured.baseURI=“http://jira/rest/api/2/issue/”;
PreemptiveBasicAuthScheme=新的PreemptiveBasicAuthScheme();
authScheme.setUserName(“#########”);
authScheme.setPassword(“########”);
RestAssured.authentication=authScheme;
getterSetter值=新getterSetter();
价值。setProject(13204);
值。setSummary(“通过REST Assured进行检查”);
值。setIssueType(3);
值。setReporter(“#########”);
设置优先级(3);
setDescription(“欢迎来到JAVA世界”);
//更新sprint名称自定义字段值
setCustomfield_10201(10608);
Gson Gson=新的Gson();
字符串json=gson.toJson(值);
System.out.println(“JSON值”+JSON);
RequestSpecification httpRequest=RestAssured.given().header(“内容类型”,
“应用程序/json”).body(json);
System.out.println(httpRequest+“请求”);
Response-Response=httpRequest.request(Method.POST,“”);
System.out.println(response.getStatusCode());
字符串responseBody=response.getBody().asString();
System.out.println(“响应”+响应体);
JsonPath JsonPath=新的JsonPath(ResponseBy);
}
}
Getter和Setter文件:

包装jira;
导入javax.xml.bind.annotation.XmlRootElement;
//@XmlRootElement
公共类getterSetter{
私人int项目;
私有int发行类型;
私人字符串记者;
私有字符串摘要;
私人优先权;
私有字符串描述;
私人国际定制区_10201;
公共字符串getSummary(){
返回摘要;
}
公共void集合摘要(字符串摘要){
this.summary=摘要;
}
公共项目(int项目){
这个项目=项目;
}
公共项目{
返回项目;
}
public int getIssueType(){
返回issueType;
}
public void setIssueType(int-issueType){
this.issueType=issueType;
}
公共字符串getReporter(){
回归记者;
}
公共void setReporter(字符串报告器){
this.reporter=记者;
}
public int getPriority(){
返回优先级;
}
公共无效设置优先级(整数优先级){
优先权=优先权;
}
公共字符串getDescription(){
返回说明;
}
公共void集合描述(字符串描述){
this.description=描述;
}
public int getCustomfield_10201(){
返回customfield_10201;
}
公共无效设置customfield_10201(int customfield_10201){
this.customfield_10201=customfield_10201;
}
}
我理解我通过请求体传递的JSON格式是错误的。谁能帮我在请求正文中传递正确的JSON格式。 我在Postman中测试了在我的实例中成功创建的上述JSON格式问题

对于上面的代码,我用
响应代码500和内部服务器错误。

根据JSON字符串作为创建Jira问题的有效负载,您可以直接创建几个相应的类,如下所示:

class IssueInfo {
    private Field fields;
    //general getters and setters
}

class Field {
    private Project project;
    private String summary;
    private IssueType issuetype;
    private Reporter reporter;
    private Priority priority;
    private String description;
    private Customfield10201 customfield_10201;
    //general getters and setters
}

class Project {
    private String id;
    //general getters and setters
}

class IssueType {
    private String id;
    //general getters and setters
}

class Reporter {
    private String name;
    //general getters and setters
}

class Priority {
    private String id;
    //general getters and setters
}

class Customfield10201 {
    private String id;
    //general getters and setters
}

分配每个必填字段的值后,您可以将
IssueInfo
的实例作为请求主体传递。

您的
getterSetter
类不符合创建问题的JSON格式。您可以通过
System.out.println(“JSON值”+JSON)看到差异已存在于代码中。是的,我的getter&setter类不符合JSON格式。你能告诉我怎么写吗。