{"record":{"id":"3f403428c70655de","repo":"FasterXML/jackson-databind","slug":"cannot-use-includeas-of-for-default-typing","errorCode":null,"errorMessage":"Cannot use includeAs of {} for Default Typing","messagePattern":"Cannot use includeAs of (.+?) for Default Typing","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/tools/jackson/databind/cfg/MapperBuilder.java","lineNumber":1785,"sourceCode":"     * and attempts of do so will throw an {@link IllegalArgumentException} to make\n     * this limitation explicit.\n     *<p>\n     * NOTE: choice of {@link PolymorphicTypeValidator} to configure is of\n     * crucial importance to security when deserializing untrusted content:\n     * this because allowing deserializing of any type can lead to malicious\n     * attacks using \"deserialization gadgets\". Implementations should use\n     * allow-listing to specify acceptable types unless source of content\n     * is fully trusted to only send safe types.\n     *\n     * @param applicability Defines kinds of types for which additional type information\n     *    is added; see {@link DefaultTyping} for more information.\n     */\n    public B activateDefaultTyping(PolymorphicTypeValidator subtypeValidator,\n            DefaultTyping applicability, JsonTypeInfo.As includeAs)\n    {\n        // Use if \"As.EXTERNAL_PROPERTY\" will not work, check to ensure no attempts made\n        if (includeAs == JsonTypeInfo.As.EXTERNAL_PROPERTY) {\n            throw new IllegalArgumentException(\"Cannot use includeAs of \"+includeAs+\" for Default Typing\");\n        }\n        return setDefaultTyping(_defaultDefaultTypingResolver(subtypeValidator,\n                applicability, includeAs));\n    }\n\n    /**\n     * Method for enabling automatic inclusion of type information -- needed\n     * for proper deserialization of polymorphic types (unless types\n     * have been annotated with {@link com.fasterxml.jackson.annotation.JsonTypeInfo}) --\n     * using \"As.PROPERTY\" inclusion mechanism and specified property name\n     * to use for inclusion (default being \"@class\" since default type information\n     * always uses class name as type identifier)\n     *<p>\n     * NOTE: choice of {@link PolymorphicTypeValidator} to configure is of\n     * crucial importance to security when deserializing untrusted content:\n     * this because allowing deserializing of any type can lead to malicious\n     * attacks using \"deserialization gadgets\". Implementations should use\n     * allow-listing to specify acceptable types unless source of content","sourceCodeStart":1767,"sourceCodeEnd":1803,"githubUrl":"https://github.com/FasterXML/jackson-databind/blob/a50c7d2a1d57234ac4adf70dbd88ac90db6436e4/src/main/java/tools/jackson/databind/cfg/MapperBuilder.java#L1767-L1803","documentation":"Thrown by MapperBuilder.activateDefaultTyping when the requested JsonTypeInfo.As is EXTERNAL_PROPERTY. External-property inclusion is fundamentally incompatible with global default typing because it needs per-property decisions the global resolver cannot make, so the builder rejects it explicitly instead of failing silently at (de)serialization time.","triggerScenarios":"Calling mapperBuilder.activateDefaultTyping(validator, applicability, JsonTypeInfo.As.EXTERNAL_PROPERTY).","commonSituations":"Porting per-type @JsonTypeInfo(include = As.EXTERNAL_PROPERTY) code and assuming the same mode works globally; copy-pasting an As constant without checking which are permitted for default typing; AI/autocomplete picking the wrong enum value.","solutions":["Use a supported inclusion for default typing: JsonTypeInfo.As.PROPERTY, WRAPPER_ARRAY, or WRAPPER_OBJECT.","If you genuinely need EXTERNAL_PROPERTY semantics, apply @JsonTypeInfo per-type/per-property instead of enabling global default typing.","Use activateDefaultTypingAsProperty(validator, applicability, propertyName) which selects PROPERTY for you."],"exampleFix":"// before\nbuilder.activateDefaultTyping(ptv, DefaultTyping.NON_FINAL,\n        JsonTypeInfo.As.EXTERNAL_PROPERTY); // throws\n// after\nbuilder.activateDefaultTyping(ptv, DefaultTyping.NON_FINAL,\n        JsonTypeInfo.As.PROPERTY);","handlingStrategy":"validation","validationCode":"JsonTypeInfo.As includeAs = resolveIncludeAs();\nif (includeAs == JsonTypeInfo.As.EXTERNAL_PROPERTY) {\n    throw new IllegalArgumentException(\n        \"EXTERNAL_PROPERTY is not supported for default typing; use per-type @JsonTypeInfo\");\n}\nbuilder.activateDefaultTyping(ptv, applicability, includeAs);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Restrict default-typing inclusion to PROPERTY, WRAPPER_ARRAY, or WRAPPER_OBJECT.","Reach for per-type @JsonTypeInfo when you need EXTERNAL_PROPERTY behavior.","Prefer activateDefaultTypingAsProperty(...) to avoid picking an unsupported As value."],"tags":["default-typing","polymorphism","configuration"],"analyzedSha":"a50c7d2a1d57234ac4adf70dbd88ac90db6436e4","analyzedAt":"2026-08-06T20:31:51.404Z","schemaVersion":2},"datasetVersion":"2026-08-07T02:17:10.218Z"}