Я хочу изменить формат отображения Json.
Я попытался напечатать весь объект Item, и он печатает все атрибуты (выглядит нормально).Я пытался изменить контроллер и службу для возврата String, и я пытался манипулировать String, но я думаю, что это не очень хороший подход к проблеме.Должно быть что-то лучше.
{
"requestedUrl":"https://www.googleapis.com/books/v1/volumes?q=java&maxResults=40",
"items":[
{
"id":"-SYM4PW-YAgC",
"volumeInfo":{
"title":"The Religion of Java",
"authors":[
"Clifford Geertz"
],
"industryIdentifiers":[
{
"type":"ISBN_10",
"identifier":"0226285103"
},
{
"type":"ISBN_13",
"identifier":"9780226285108"
}
],
"readingModes":{
"text":true,
"image":true
},
"pageCount":392,
"printType":"BOOK",
"categories":[
"Religion"
]
}
}
]
}
BookController.java
@CrossOrigin
@RestController
@RequestMapping("/")
public class BookController {
private BookService service;
public BookController(BookService service) {
this.service = service;
}
@GetMapping("book/{isbn}")
public Item getBook(@PathVariable String isbn) {
return service.findBookByISBN(isbn);
}
}
BookService.java
public class BookService {
public BookService() throws IOException {
}
public Item findBookByISBN(String isbn) {
// listOfItems taking json file from json file and making List<Item> to itarate over
for (Item item : listOfItems) {
if (item.getVolumeInfo().getIndustryIdentifiers().get(0).getIdentifier().equals(isbn)) {
return item;
}
}
return null;
}
}
Кур У меня есть класс POJO ...
Для findBookByISBN(9780226285108)
json answerear is
{
"title":"The Religion of Java",
"authors":[
"Clifford Geertz"
],
"industryIdentifiers":[
{
"type":"ISBN_10",
"identifier":"0226285103"
},
{
"type":"ISBN_13",
"identifier":"9780226285108"
}
],
"readingModes":{
"text":true,
"image":true
},
"pageCount":392,
"printType":"BOOK",
"categories":[
"Religion"
]
}
Но я хочу сделать свой JSON таким:
{
"title":"The Religion of Java",
"printType":"BOOK",
"pageCount":392,
"authors":[
"Clifford Geertz"
],
"categories":[
"Religion"
]
}