0

I have a interesting problem. Basically I have requirement where we need to generate HMAC SH256 out of RAW json body which is pretty easy. Problem is that our model is a little bit tricky and I don't know how to handle this correctly so it will work. So basically we receive JSON request looking like this:

{
    "type":"ef3be186-fba4-4778-ad29-8b8f87a10de8",
    "body":{
        "isActive":true,
        "balance":"$3,858.83",
        "tags":[
            "labore",
            "aliquip",
            "velit",
            "consequat",
            "tempor",
            "in",
            "sint"
        ],
        "friends":[
            {
                "id":0,
                "name":"Gay Roth"
            },
            {
                "id":1,
                "name":"Glenda Farmer"
            },
            {
                "id":2,
                "name":"Suzanne Puckett"
            }
        ],
        "greeting":"Hello, Blanca Sharp! You have 2 unread messages.",
        "favoriteFruit":"strawberry"
    }
}

Nothing special at this moment problem is that everything on body tag need to stay exactly the same os new lanes / indention etc. We are using Jackson to map pojos and our pojo looks like this (but it doesn't work):

@NoArgsConstructor
@AllArgsConstructor
@Data
@EqualsAndHashCode
public class RandomRequest {

    private String type;

    @JsonRawValue
    private String body;

}

Error:

java.io.UncheckedIOException: com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of java.lang.String out of START_OBJECT

So my question is simple. Is there any way to tell jackson to map just type and leave body part untouched as a pure JSON ? (not JSONNode / Object - those will lose all formatting - we need just pure raw JSON string)

user3353393
  • 139
  • 3
  • 12
  • THis is not possible - see https://stackoverflow.com/questions/4783421/how-can-i-include-raw-json-in-an-object-using-jackson for a similar question. – jon hanson Mar 05 '23 at 14:04

0 Answers0