Skip to content

Ignore a @JsonSubType in the JSON schema by custom annotation #347

Closed Answered by CarstenWickner
roded asked this question in Q&A
Discussion options

You must be logged in to vote

HI @roded,

This is certainly possible, just not out-of-the-box.

I suggest you use the JacksonModule as per your current configuration but include the JacksonOption.SKIP_SUBTYPE_LOOKUP and JacksonOption.IGNORE_TYPE_INFO_TRANSFORM.
Then you apply its JsonSubTypesResolver yourself -- with a little override, e.g.

JsonSubTypesResolver subtypeResolver = new JsonSubTypesResolver(jacksonOptions) {
    public List<ResolvedType> lookUpSubtypesFromAnnotation(ResolvedType declaredType, JsonSubTypes subtypesAnnotation, TypeContext context) {
        List<ResolvedType> subtypes = super.lookUpSubtypesFromAnnotation(declaredType, subtypesAnnotation, context);
        /* remove undesired subtypes from the…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@roded
Comment options

@roded
Comment options

Answer selected by roded
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants