0

I need to consume this API: https://api.punkapi.com/v2/beers and after consuming, I have to store it in the database, but only with next fields: internal id, name, description and mean value of the temperature. Any ideas or advice?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
markz
  • 5
  • 1

1 Answers1

0

The simplest approach would be to have your Model only containing those attributes so that Spring only deserialize them from JSON to object. Something like the following:

public class YourModel {
   private long id;
   private String name;
   private String description;
}

Then in your Service you would have:

ResponseEntity<YourModel> response = restTemplate.getForEntity(url, YourModel.class);

You can then either save YourModel directly to the database (first you need to add some @Annotations if you want to rely on JPA) or you may build another more suited model to your use case.

João Dias
  • 16,277
  • 6
  • 33
  • 45