import com.fasterxml.jackson.annotation.JsonSubTypes; import com.fasterxml.jackson.annotation.JsonTypeInfo; import tools.jackson.databind.json.JsonMapper; public class JsonForgotten { // Wallet is a permitted subtype, and the compiler is happy, but nobody told Jackson about it. @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type") @JsonSubTypes({ @JsonSubTypes.Type(value = Card.class, name = "card"), @JsonSubTypes.Type(value = Upi.class, name = "upi")}) sealed interface Payment permits Card, Upi, Wallet {} record Card(long amount) implements Payment {} record Upi(long amount) implements Payment {} record Wallet(long amount) implements Payment {} public static void main(String[] args) { JsonMapper mapper = JsonMapper.builder().build(); System.out.println("write : " + mapper.writeValueAsString(new Wallet(500))); try { mapper.readValue("{\"type\":\"wallet\",\"amount\":500}", Payment.class); } catch (Exception e) { System.out.println("read : " + e.getClass().getSimpleName() + ": " + e.getMessage().lines().findFirst().orElse("")); } } }