Jackson parse json with unwraping root, but without ability to set @JsonRootName

You can do it with mixin feature. You can create simple interface/abstract class like this:

@JsonRootName("transaction")
interface TransactionMixIn {

}

Now, you have to configure ObjectMapper object:

ObjectMapper mapper = new ObjectMapper();
mapper.enable(DeserializationFeature.UNWRAP_ROOT_VALUE);
mapper.addMixInAnnotations(Transaction.class, TransactionMixIn.class);

And finally you can use it to deserialize JSON:

mapper.readValue(json, Transaction.class);

Second option – you can write custom deserializer for Transaction class.

Leave a Comment