I have a usecase where the request payload contains a payload like given below
"list_of_conditions": [
{
"field_id": "QTrg9vq4S5uUs0yMnCpSVQ",
"value": "monitor",
"show": [
{
"field_id": "7Q41FQvWSR2u4E5PiT39DQ",
"required": true
},
{
"field_id": "FCqIf70iQJi48H-dC6xMEg"
},
{
"field_id": "vaTvFctJQgmhZq4F_liUBg"
}
],
"modify": [
{
"field_id": "7Q41FQvWSR2u4E5PiT39DQ",
"required": true,
"newValue": "hello"
}
]
},
{
"field_id": "QTrg9vq4S5uUs0yMnCpSVQ",
"value": "monitor",
"show": [
{
"field_id": "7Q41FQvWSR2u4E5PiT39DQ",
"required": true
},
{
"field_id": "FCqIf70iQJi48H-dC6xMEg"
},
{
"field_id": "vaTvFctJQgmhZq4F_liUBg"
}
]
}
]
In the above snippet, every object inside list_of_conditions has some operations like "show", "modify" and this list can grow in future as functionality increases. My objective here is to ingest this payload from the request payload in the controller and persist in DB. I tried writing below DTO but it doesn't work for all the use cases. Ideally a request payload can contain other operation like "modify" and DTO should be able to deserialise it
@Data
@Builder
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_EMPTY)
@NoArgsConstructor
@AllArgsConstructor
public class ListOfCondition {
@JsonProperty("id")
private String id;
@JsonProperty("field_id")
private String fieldId;
@JsonProperty("value")
private String value;
@JsonProperty("show")
private List<ActionDTO> childFields;
}
What I really want here is, my DTO should be able to deserialise payload given above. Currently, it is only doing it for a payload containing "show" as key because of below snippet. How can I make it generic and accept other keys as well
@JsonProperty("show")
private List<ConditionActionDTO> childFields;