How to fix “com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field” Error Message – Rest API

5,324 views
Skip to first unread message

Poovaraj

unread,
Dec 29, 2017, 12:47:33 PM12/29/17
to REST assured
Hi ,

I got below error message while executing Rest API command. Can you please help me how to fix this error ?

Code:

RestAssured.baseURI = “http://restapi.demoqa.com/utilities/books/getallbooks”;
RequestSpecification httpRequest = RestAssured.given();
Response response = httpRequest.get(“”);

// First get the JsonPath object instance from the Response interface 
JsonPath jsonPathEvaluator = response.jsonPath();

// Read all the books as a List of String. Each item in the list
// represent a book node in the REST service Response
List<Book> allBooks = jsonPathEvaluator.getList(“books”, Book.class);

// Iterate over the list and print individual book item
// Note that every book entry in the list will be complete Json object of book
for(Book book : allBooks)
{
System.out.println(“Book: ” + book.title);
}

 

Error Message:

com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field “website” (class LearningRestAssured.RestAssured.Book), not marked as ignorable (0 known properties: ])
at [Source: (String)”{“website”:”http://eloquentjavascript.net/”,”pages”:472,”author”:”Marijn Haverbeke”,”isbn”:”9781593275846″,”subtitle”:”A Modern Introduction to Programming”,”publisher”:”No Starch Press”,”description”:”JavaScript lies at the heart of almost every modern web application, from social apps to the newest browser-based games. Though simple for beginners to pick up and play with, JavaScript is a flexible, complex language that you can use to build full-scale applications.”,”published”:”2014-12-14T00:0″[truncated 57 chars]; line: 1, column: 13] (through reference chain: LearningRestAssured.RestAssured.Book[“website”])
at com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException.from(UnrecognizedPropertyException.java:60)
at com.fasterxml.jackson.databind.DeserializationContext.handleUnknownProperty(DeserializationContext.java:822)
at com.fasterxml.jackson.databind.deser.std.StdDeserializer.handleUnknownProperty(StdDeserializer.java:1152)
at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.handleUnknownProperty(BeanDeserializerBase.java:1567)
at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.handleUnknownVanilla(BeanDeserializerBase.java:1545)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:293)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:151)
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4001)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3030)
at com.fasterxml.jackson.databind.ObjectMapper$readValue$0.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:133)
at io.restassured.internal.path.json.mapping.JsonPathJackson2ObjectDeserializer.deserialize(JsonPathJackson2ObjectDeserializer.groovy:45)
at io.restassured.path.json.mapping.JsonPathObjectDeserializer$deserialize.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
at io.restassured.internal.path.json.mapping.JsonObjectDeserializer.deserializeWithJackson2(JsonObjectDeserializer.groovy:98)
at io.restassured.internal.path.json.mapping.JsonObjectDeserializer$deserializeWithJackson2.callStatic(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallStatic(CallSiteArray.java:56)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callStatic(AbstractCallSite.java:194)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callStatic(AbstractCallSite.java:214)
at io.restassured.internal.path.json.mapping.JsonObjectDeserializer.deserialize(JsonObjectDeserializer.groovy:67)
at io.restassured.path.json.JsonPath.jsonStringToObject(JsonPath.java:1016)
at io.restassured.path.json.JsonPath.getList(JsonPath.java:398)
at LearningRestAssured.RestAssured.JsonResponseUsingDeserialize.JsonPathUsage(JsonResponseUsingDeserialize.java:34)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.base/java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:571)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:707)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:979)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
at org.testng.TestRunner.privateRun(TestRunner.java:648)
at org.testng.TestRunner.run(TestRunner.java:505)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:455)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415)
at org.testng.SuiteRunner.run(SuiteRunner.java:364)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1187)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1116)
at org.testng.TestNG.runSuites(TestNG.java:1028)
at org.testng.TestNG.run(TestNG.java:996)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)


Regards,

Poovaraj

Johan Haleby

unread,
Dec 29, 2017, 12:55:39 PM12/29/17
to rest-a...@googlegroups.com
This is a jackson related issue, but it'll probably work if you simply add @JsonIgnoreProperties(ignoreUnknown = true) to the top-level of the Book class.

--
You received this message because you are subscribed to the Google Groups "REST assured" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rest-assured+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Poovaraj

unread,
Dec 30, 2017, 9:16:38 AM12/30/17
to REST assured
Hi Johan Haleby,

Thanks for your reply.

It is showing null value after adding @JsonIgnoreProperties(ignoreUnknown = true) annotation. Why is it showing null value ?

 Code :

@JsonIgnoreProperties(ignoreUnknown = true)
public class Book
{
String isbn;
    String title;
    String subtitle;
    String author;
    String published;
    String publisher;
    int pages;
    String description;  
    
    String website;
}

Output :

Book: null
Book: null
Book: null
Book: null
Book: null
Book: null
Book: null
Book: null
PASSED: JsonPathUsage
To unsubscribe from this group and stop receiving emails from it, send an email to rest-assured...@googlegroups.com.

Poovaraj Thangamariappan

unread,
Dec 30, 2017, 12:18:47 PM12/30/17
to REST assured
Hi Johan Haleby,

Thanks for your reply !

It is returning "NULL" value after adding  @JsonIgnoreProperties(ignoreUnknown = true).  Why is it returning null value ?

Code :

@JsonIgnoreProperties(ignoreUnknown = true)
public class Book
{
String isbn;
    String title;
    String subtitle;
    String author;
    String published;
    String publisher;
    int pages;
    String description;  
    
    String website;
}


Output:

Book: null
Book: null
Book: null
Book: null
Book: null
Book: null
Book: null
Book: null
PASSED: JsonPathUsage



To unsubscribe from this group and stop receiving emails from it, send an email to rest-assured...@googlegroups.com.

Johan Haleby

unread,
Dec 31, 2017, 8:25:58 AM12/31/17
to rest-a...@googlegroups.com
Maybe if you try to log the response you'll get some hints.

To unsubscribe from this group and stop receiving emails from it, send an email to rest-assured+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages