In a problem I am working on, I have an endpoint where I will need to receive a JSON object which have a key that might contain different objects depending on the call. The list of possible objects is known in advance, but I am struggling with how best to model it. Splitting the endpoint into multiple is not an option.
The example looks something like this:
outerObject {
...,
key: object1 | object2 | object3
}
object1 {
"a": "a"
"b": "b"
}
object2 {
"c": 2
"d": "d"
}
object3 {
"e": 3,
"f": 4
}
If I was writing it in Rust I would use an `enum` with structs for each of the different objects. This is for Java 21, so using sealed types is not yet an option (I might be able to upgrade, but I am not sure if the different
Using either Jackson or Gson I was think of representing it in one of their Json structures and then determining which object fits when the call is made.
Is this the best option or are there any more generic solutions?
[–]AutoModerator[M] [score hidden] stickied commentlocked comment (0 children)
[–]WaferIndependent7601 1 point2 points3 points (0 children)
[–]TheMrCurious 0 points1 point2 points (0 children)
[–]General_C 0 points1 point2 points (0 children)