Skip to content

activateDefaultTypingAsProperty is not using the parameter PolymorphicTypeValidator #2840

@DanielYWoo

Description

@DanielYWoo

The ptv is not used, but the javadoc says it is to be used, is it a bug?

   /**
     * Method for enabling automatic inclusion of type information ("Default Typing")
     * -- needed for proper deserialization of polymorphic types (unless types
     * have been annotated with {@link com.fasterxml.jackson.annotation.JsonTypeInfo}) --
     * using "As.PROPERTY" inclusion mechanism and specified property name
     * to use for inclusion (default being "@class" since default type information
     * always uses class name as type identifier)
     *<p>
     * NOTE: choice of {@link PolymorphicTypeValidator} to pass is critical for security
     * as allowing all subtypes can be risky for untrusted content.
     *
     * @param ptv Validator used to verify that actual subtypes to deserialize are valid against
     *    whatever criteria validator uses: important in case where untrusted content is deserialized.
     * @param applicability Defines kinds of types for which additional type information
     *    is added; see {@link DefaultTyping} for more information.
     * @param propertyName Name of property used for including type id for polymorphic values.
     *
     * @since 2.10
     */
    public ObjectMapper activateDefaultTypingAsProperty(PolymorphicTypeValidator ptv,
            DefaultTyping applicability, String propertyName)
    {
        TypeResolverBuilder<?> typer = _constructDefaultTypeResolverBuilder(applicability,
                getPolymorphicTypeValidator());

        // we'll always use full class name, when using defaulting
        typer = typer.init(JsonTypeInfo.Id.CLASS, null);
        typer = typer.inclusion(JsonTypeInfo.As.PROPERTY);
        typer = typer.typeProperty(propertyName);
        return setDefaultTyping(typer);
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions