is there a simpler way of writing this class? I f...
# announcements
s
is there a simpler way of writing this class? I feel like my coworker could just use lateinit, but I don't know if jsonproperty allows that...
b
A simple
data class
is not enough?
s
data class would allow you to set all three params. He's restricted it with private set, and individual constructors.
b
like this:
Copy code
data class SupportRequirements(
        @JsonProperty(value = "and") val andSupportRequirements: Array<String>? = null,
        @JsonProperty(value = "or") val orSupportRequirements: Array<String>? = null,
        val supportRequirement: String? = null
) : Serializable
u can set like this:
Copy code
SupportRequirements(supportRequirement = "")
s
it doesn't restrict it though.
it's still possible to set all three.
you have no protection against it. It's not a Union.
He's going for a union.
b
maybe u can create functions to instantiate the data class
s
no, we're using a framework. It will create this class itself. Oh well.
thanks for trying.
f
I'm guessing this object is received from a client and is deserialized with Jackson right?
s
we're using the axon framework, so the 'client' is another microservice, but yes.
i believe so.
f
you might be able to do something with Jackson's polymorphic deserialization stuff, let me try something
s
huh. haven't heard of that!
s
ahhh. the adding class info. I have done that before actually.
I'll mention it to him. thanks
f
I'm not sure you can use the actual names of the properties to select which implementation is going to be used but you can add a "@type" property and switch on this
np