I'm trying to force gson to throw an exception when an string does not map to an object which I'm passing to it.
@ResponseStatus(HttpStatus.CREATED)
@PostMapping("offer")
public String postOffer(@RequestBody String jsonBody) {
Offer offer = gson.fromJson(jsonBody, Offer.class);
offerRepository.save(offer);
return offer.getId();
}
Currently, it will just save what ever it can to the db and ignore any elements that don't map to the class. This is bad for me because I get bad data making it's way to the db.
Any help would be appreciated.
ps. using springboot-data-mongodb and gson for mapping.
Thanks