deserialise JSON into multiple object through restTemplate

998 Views Asked by At

I have a task in hand for which I have to make a rest call through Spring's restTemplate , parse the JSON data and insert it into the database.

To quote an simple example lets assume the JSON response something like this

{ "book_title": "Example book title", "book_price": "25 USD" }

For the database design I am considered to have two tables.

Book_Catalog (book_id, book_title)
Book_Pirce (book_id, book_price)

Thus for these two db tables I am creating two model objects (BookCatalog and BookPrice)

I am fetching the data with restTemplate like this

    ResponseEntity<BookCatalog> response = restTemplate.exchange(url, HttpMethod.GET, request, BookCatalog.class);

This way I get the response data only in one object, is there a way I can populate data in both the objects with Single rest call?

1

There are 1 best solutions below

2
On

The only solution I can think of is getting response as string then converting it to desired pojo in code by a library jackson or something like that.