// 主要是给swagger使用的,可以让swagger文档也能显示出来同一个接口多组不同的参数,后端会通过Jackson转换成不同的实现类类接受参数。
@Schema(oneOf = {Status1.class,Status2.class,Status3.class})
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME,
include = JsonTypeInfo.As.EXISTING_PROPERTY, property = "type", visible = true)
// 主要用于标识有哪些多态子类,并指定使用name来确定转换成那个实现类
// 这里的name的值对应子类注解JsonTypeName的值
@JsonSubTypes({
@JsonSubTypes.Type(value = Status1.class, name = "s1"),
@JsonSubTypes.Type(value = Status2.class, name = "s2"),
@JsonSubTypes.Type(value = Status3.class, name = "s3")
})
public interface StatusInput {
}
// @JsonTypeName("s1") 用于给父类来标识转换成当前类的依据
@JsonTypeName("s1")
public record StatusInput1(
@NotNull
@Schema(type = STRING, required = true, enumeration = {"S1"})
StatusType type,
@PositiveOrZero
@Schema(type = NUMBER, required = true, description = "Remaining meters until maneuver is completed")
double remainingMeters,
@NotNull
@Schema(type = STRING, required = true, enumeration = {"INITIALIZING", "PARKING", "DRIVE", "ERROR"})
Gear gear,
@PositiveOrZero
@Schema(type = NUMBER, required = true, description = "Speed in km/h")
double speed,
@Schema(type = DEFAULT, required = true)
Color color
) implements StatusInput {
}
@JsonTypeName("s2")
public record StatusInput2(
@NotNull
@Schema(type = STRING, required = true,
enumeration = {"S2"})
StatusType type,
@NotNull
@Schema(type = OBJECT, required = true)
Color color
) implements StatusInput {
}
@JsonTypeName("S3")
public record StatusInput3(
@NotNull
@Schema(type = STRING, required = true,
enumeration = {"s3"})
StatusType type,
@NotNull
@Schema(type = STRING, required = true, enumeration = {"LANE_BLOCKED", "LANE_NOT_BLOCKED"})
EndPositionType endPositionType,
@NotNull
@Schema(type = STRING, required = true, enumeration = {"VRU_BLOCKING_PATH","VEHICLE_BLOCKING_PATH"})
EndReachedReason reason,
@NotNull
@Schema(type = OBJECT, required = true)
Color color
) implements StatusInput {
}