Home > Blockchain >  Unrecognized field "id" (class pojoClasses.BookingDetails), not marked as ignorable
Unrecognized field "id" (class pojoClasses.BookingDetails), not marked as ignorable

Time:11-22

i am running a RestApi, through rest assured for updating that getting the error unable to resolve issue in the Bookingdetails there is no id. but at the line iam getting the error in the line

Unrecognized field "id" (class pojoClasses.BookingDetails), not marked as ignorable (3 known properties: "title", "author", "createdat"])

I have class

BookingDetails.java

package pojoClasses;

import com.fasterxml.jackson.annotation.JsonProperty;

public class BookingDetails {
    
    @JsonProperty
    private String title;
    
    @JsonProperty
    private String author;

    @JsonProperty
    private String createdat;

    public String gettitle(String title) {
        return this.title;
    }
    
    public void settitle(String title) {
        this.title = title;
    }
    
    public String getAuthor(String author) {
        return this.author;
    }
    
    public void setAuthor(String author) {
        this.author = author;
    }


    public String getCreatedat(String createdat) {
        return this.createdat;
    }

    public void setcreatedat(String createdat) {
        this.createdat = createdat;
    }

}

UpdateBooking.java

import io.restassured.response.Response;
import org.testng.annotations.Test;
import pojoClasses.BookingDetails;
import utility.AllureLogger;
import utility.BaseTest;

import static io.restassured.RestAssured.given;

public class UpdateBooking extends BaseTest {
    
    @Test(description="To update the details of the booking IDs") 
    public void updateBooking(){
        
        AllureLogger.logToAllure("Starting the test to update details");
        //Sending the PUT request for a specific booking id and receiving the response after updating the detals
        AllureLogger.logToAllure("PUT update booking detail");
        //Created a new booking
        CreateBooking createBooking = new CreateBooking();
        createBooking.createNewBooking("time", "psos", "2018-01-03", "null");
        String IDtoUpdate = createBooking.newID;
        AllureLogger.logToAllure("New Booking ID created is : " IDtoUpdate);
        System.out.println("IDtoUpdate:::::::   " IDtoUpdate);
        //Update the booking with new first name
        Response getResponse = given().
                spec(requestSpec).
                pathParam("id", IDtoUpdate).
            when().
                get("/posts/{id}");

        BookingDetails bookingDetails = getResponse.as(BookingDetails.class);
        bookingDetails.settitle("employee");
        Response response = given().
            spec(requestSpec).
            header("Content-Type", "application/json").
            header("Accept", "application/json").
//          header("Cookie", cookieValue).
            pathParam("id", IDtoUpdate).
//          pathParam("id", 3).
            body(bookingDetails).log().body().
        when().
            put("/posts/{id}");
        
        //Verify the response code
        AllureLogger.logToAllure("Asserting the response if the status code returned is 200");
        response.then().spec(responseSpec);     

        //To log the response to report
        logResponseAsString(response);
        
    }
}

when run through command -> mvn install

Output

Body:
{
    "title": "time",
    "author": "psos",
    "createdat": "2018-01-03"
}
{
  "title": "time",
  "author": "psos",
  "createdat": "2018-01-03",
  "id": 32
}
32
IDtoUpdate:::::::   32
[ERROR] Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 21.409 s <<< FAILURE! - in TestSuite
[ERROR] updateBooking(UpdateBooking)  Time elapsed: 10.263 s  <<< FAILURE!
com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException:
Unrecognized field "id" (class pojoClasses.BookingDetails), not marked as ignorable (3 known properties: "title", "author", "createdat"])
 at [Source: (String)"{
  "title": "time",
  "author": "psos",
  "createdat": "2018-01-03",
  "id": 32
}"; line: 5, column: 11] (through reference chain: pojoClasses.BookingDetails["id"])
        at UpdateBooking.updateBooking(UpdateBooking.java:30)

CodePudding user response:

I dont see the id field in the BookingDetails DTO/POJO. Try adding it like:

private String id;

 public String getId() {
        return this.id;
    }
    
  • Related