0

In my request body I have property field names with "_" So I used @JsonProperty and mapped to camelCase names.

But the problem is I need to authenticate the request based on the hashed string value coming in header. This the initial request hash sha512 with a key.

But in my case since I used @JsonProperty, a field for which initial name is currency_received is deserialized to currencyReceived

@JsonProperty("currency_received")
private CurrencyReceived currencyReceived;

And I try to get the hashed value of request using

String reqObj = gson.toJson(req);
String hashVal = HashGeneratorUtils.generateHmacSHA512(reqObj, pvt_key);

the hashVal will never be same as the value coming in header hashed with original request.

So, what is the ideal way to solve this problem.

arqam
  • 3,582
  • 5
  • 34
  • 69
  • 1
    You can't de/-serialize if you need a hash of the original request, e.g. whitespaces get removed too. You'll need access to the raw request body in string or byte form for that and that depends on your platform. E.g. with spring you can pass the body as string (`@RequestBody String data`), then use gson afterwards to create your objects. Validation like that could also be a an access filter (https://stackoverflow.com/a/39154300/995891) – zapl Sep 27 '22 at 15:29
  • `@JsonProperty` is not from Gson, it might be from Jackson. Gson has `@SerializedName`. It might make sense to only use one library and not mix multiple since that could lead to confusion. – Marcono1234 Sep 27 '22 at 17:33

0 Answers0