File tree Expand file tree Collapse file tree 2 files changed +23
-0
lines changed
main/java/com/fasterxml/jackson/databind
test/java/com/fasterxml/jackson/databind/jsontype Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -1073,12 +1073,23 @@ public ObjectMapper enableDefaultTyping(DefaultTyping dti) {
1073
1073
* Method for enabling automatic inclusion of type information, needed
1074
1074
* for proper deserialization of polymorphic types (unless types
1075
1075
* have been annotated with {@link com.fasterxml.jackson.annotation.JsonTypeInfo}).
1076
+ *<P>
1077
+ * NOTE: use of {@link JsonTypeInfo.As#EXTERNAL_PROPERTY} is <b>NOT SUPPORTED</b>;
1078
+ * and attempts of do so will throw an {@link IllegalArgumentException} to make
1079
+ * this limitation explicit.
1076
1080
*
1077
1081
* @param applicability Defines kinds of types for which additional type information
1078
1082
* is added; see {@link DefaultTyping} for more information.
1079
1083
*/
1080
1084
public ObjectMapper enableDefaultTyping (DefaultTyping applicability , JsonTypeInfo .As includeAs )
1081
1085
{
1086
+ /* 18-Sep-2014, tatu: Let's add explicit check to ensure no one tries to
1087
+ * use "As.EXTERNAL_PROPERTY", since that will not work.
1088
+ */
1089
+ if (includeAs == JsonTypeInfo .As .EXTERNAL_PROPERTY ) {
1090
+ throw new IllegalArgumentException ("Can not use includeAs of " +includeAs );
1091
+ }
1092
+
1082
1093
TypeResolverBuilder <?> typer = new DefaultTypeResolverBuilder (applicability );
1083
1094
// we'll always use full class name, when using defaulting
1084
1095
typer = typer .init (JsonTypeInfo .Id .CLASS , null );
Original file line number Diff line number Diff line change @@ -349,6 +349,18 @@ public void testFeature432() throws Exception
349
349
String json = mapper .writeValueAsString (new BeanHolder (new StringBean ("punny" )));
350
350
assertEquals ("{\" bean\" :{\" *CLASS*\" :\" com.fasterxml.jackson.databind.jsontype.TestDefaultForObject$StringBean\" ,\" name\" :\" punny\" }}" , json );
351
351
}
352
+
353
+ public void testNoGoWithExternalProperty () throws Exception
354
+ {
355
+ ObjectMapper mapper = new ObjectMapper ();
356
+ try {
357
+ mapper .enableDefaultTyping (ObjectMapper .DefaultTyping .JAVA_LANG_OBJECT ,
358
+ JsonTypeInfo .As .EXTERNAL_PROPERTY );
359
+ fail ("Should not have passed" );
360
+ } catch (IllegalArgumentException e ) {
361
+ verifyException (e , "Can not use includeAs of EXTERNAL_PROPERTY" );
362
+ }
363
+ }
352
364
353
365
/*
354
366
/**********************************************************
You can’t perform that action at this time.
0 commit comments