I am doing quite similar stuff at my current day job 👍🏻
Hope My suggestions can help.
1# “NO” to using a custom de/serializer.
I started using @JsonTypeInfo at work to avoid exactly that.
Having to write custom de/serializers for every DTO class.
2# Use Id.Name instead.
I suggest to change DEDUCTION based handling on REST layer to JsonTypeInfo.Id.NAME based.
This will require change in REST API specification, but in the long term it will be easier to debug/maintain.
Imagine how much a troublesome it would be for a server to having to “assume” every time what the client intends to do with the request!
3# Maintain `@JsonSubTypes.Type.name` attribute as constants.
Simple coding convention, maintain a variable in one place.
Since @JsonTypeInfo provides polymorphic type handling which is already complex, hard-coding type id will get back to you soon. It took me only a few days … :(
Take below code for example
# AS-IS
```java
@JsonSubTypes({
@JsonSubTypes.Type(value = AndDbDto.class, name = AND_VALUE),
@JsonSubTypes.Type(value = OrDbDto.class, name = OR_VALUE)
})
```
# TO-BE
```java
@JsonSubTypes({
@JsonSubTypes.Type(value = AndDbDto.class, name = AND_VALUE),
@JsonSubTypes.Type(value = OrDbDto.class, name = OR_VALUE),
@JsonSubTypes.Type(value = ConditionDbDto.class, name = CONDITION_VALUE)
})
public enum DbExpressions {
AND, OR, CONITION
// Constants
public static final String AND_VALUE = “and”;
public static final String OR_VALUE = “or”;
public static final String CONDITION_VALUE = “condition”;
}
```