Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/331.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
获得;javax.xml.bind.MarshalException“;使用rest assured调用rest api时发生异常_Java_Rest - Fatal编程技术网

获得;javax.xml.bind.MarshalException“;使用rest assured调用rest api时发生异常

获得;javax.xml.bind.MarshalException“;使用rest assured调用rest api时发生异常,java,rest,Java,Rest,我试图使用rest-assured调用RESTAPI,但得到了“javax.xml.bind.MarshalException”异常。 下面是我的主类代码 @Test public void registerDevice() throws IOException { config = new FileInputStream("Configuration.properties"); prop.load(config);

我试图使用rest-assured调用RESTAPI,但得到了“javax.xml.bind.MarshalException”异常。 下面是我的主类代码

  @Test
        public void registerDevice() throws IOException {
            config = new FileInputStream("Configuration.properties");
            prop.load(config);
            HashMap<String, String> phone = CommonPayLoad.payLoadData("register-device");
            RestAssured.baseURI = prop.getProperty("url");
            Response registerResponse = given().
            body(phone).
            when().
            post(CommonResource.resgisterDevice()).
            then().assertThat().statusCode(200).and().contentType(ContentType.JSON).
            extract().response();
            String resgisterResponseString = registerResponse.asString();
            JsonPath js = new JsonPath(resgisterResponseString);
            String _bb_vid = js.get("visitor_id");
            System.out.println("response String= "+resgisterResponseString);

        }
可能的副本;看起来您需要定义一个包装类,该类可能重复;看起来您需要定义一个包装器类
public static HashMap<String, String> payLoadData(String api_name) throws IOException{
        String apiName = api_name;
        HashMap<String, String> payLoad = new HashMap<String, String>();
        FileInputStream fis = new FileInputStream("Payload.xls");
        HSSFWorkbook workbookExcel = new HSSFWorkbook(fis);
        HSSFSheet worksheet = workbookExcel.getSheetAt(0);
        int rowNum = worksheet.getLastRowNum();
        for (int i=0; i<rowNum; i++) {
            HSSFRow rowHeader = worksheet.getRow(0);
            HSSFRow row = worksheet.getRow(i+1);
            short cellHeaderNum = rowHeader.getLastCellNum(); 
            short cellNum = row.getLastCellNum();

            for(int j=0; j<cellHeaderNum-1; j++) {
                    HSSFCell cellHeader = rowHeader.getCell(j+1);
                    HSSFCell apiNameCell = row.getCell(0);
                    HSSFCell cell =row.getCell(j+1);    
                    cell.setCellType(CellType.STRING);
                    String cellValue = cell.getStringCellValue();
                    String cellHeaderValue = cellHeader.getStringCellValue();
                    String apiNameCellValue = apiNameCell.getStringCellValue();
                    if(apiNameCellValue.equals(apiName)) {
                        if(!cellValue.equals("NA")) {
                            payLoad.put(cellHeaderValue, cellValue);

                            }   
                }
            }
        }
             workbookExcel.close();
             fis.close();
            return payLoad; 
    }
javax.xml.bind.MarshalException
 - with linked exception:
[com.sun.istack.internal.SAXException2: unable to marshal type "java.util.HashMap" as an element because it is missing an @XmlRootElement annotation]
    at com.sun.xml.internal.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:311)
    at com.sun.xml.internal.bind.v2.runtime.MarshallerImpl.marshal(MarshallerImpl.java:236)
    at javax.xml.bind.helpers.AbstractMarshallerImpl.marshal(AbstractMarshallerImpl.java:116)
    at javax.xml.bind.Marshaller$marshal$0.call(Unknown Source)