I want to deserialize the response from:
Therefore, @Data annotation also worked because @Data annotation is responsible for adding getter and setter into the class. So solution for your problem will be
package com.example.springlearning;
import lombok.Data;
public class Book {
String isbn;
String title;
String subTitle;
String author;
String publish_date;
String publisher;
int pages;
String description;
String website;
public String getIsbn() {
return isbn;
}
public void setIsbn(String isbn) {
this.isbn = isbn;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getSubTitle() {
return subTitle;
}
public void setSubTitle(String subTitle) {
this.subTitle = subTitle;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public String getPublish_date() {
return publish_date;
}
public void setPublish_date(String publish_date) {
this.publish_date = publish_date;
}
public String getPublisher() {
return publisher;
}
public void setPublisher(String publisher) {
this.publisher = publisher;
}
public int getPages() {
return pages;
}
public void setPages(int pages) {
this.pages = pages;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getWebsite() {
return website;
}
public void setWebsite(String website) {
this.website = website;
}
}
Hope this would help that how @Data works in deserializing your data.
CodePudding user response:
One easy way to solve this problem is make all fields of Book class is public
public class Book {
public String isbn;
public String title;
public String subTitle;
public String author;
public String publish_date;
public String publisher;
public int pages;
public String description;
public String website;
}
Other way is use @Data
from Lombok library
import lombok.Data;
@Data
public class Book {
String isbn;
String title;
String subTitle;
String author;
String publish_date;
String publisher;
int pages;
String description;
String website;
}