@@ -1525,7 +1525,43 @@ public ObjectMapper setDefaultMergeable(Boolean b) {
1525
1525
1526
1526
/*
1527
1527
/**********************************************************
1528
- /* Type information configuration
1528
+ /* Subtype registration
1529
+ /**********************************************************
1530
+ */
1531
+
1532
+ /**
1533
+ * Method for registering specified class as a subtype, so that
1534
+ * typename-based resolution can link supertypes to subtypes
1535
+ * (as an alternative to using annotations).
1536
+ * Type for given class is determined from appropriate annotation;
1537
+ * or if missing, default name (unqualified class name)
1538
+ */
1539
+ public void registerSubtypes (Class <?>... classes ) {
1540
+ getSubtypeResolver ().registerSubtypes (classes );
1541
+ }
1542
+
1543
+ /**
1544
+ * Method for registering specified class as a subtype, so that
1545
+ * typename-based resolution can link supertypes to subtypes
1546
+ * (as an alternative to using annotations).
1547
+ * Name may be provided as part of argument, but if not will
1548
+ * be based on annotations or use default name (unqualified
1549
+ * class name).
1550
+ */
1551
+ public void registerSubtypes (NamedType ... types ) {
1552
+ getSubtypeResolver ().registerSubtypes (types );
1553
+ }
1554
+
1555
+ /**
1556
+ * @since 2.9
1557
+ */
1558
+ public void registerSubtypes (Collection <Class <?>> subtypes ) {
1559
+ getSubtypeResolver ().registerSubtypes (subtypes );
1560
+ }
1561
+
1562
+ /*
1563
+ /**********************************************************
1564
+ /* Default typing (automatic polymorphic types): current (2.10)
1529
1565
/**********************************************************
1530
1566
*/
1531
1567
@@ -1535,14 +1571,13 @@ public ObjectMapper setDefaultMergeable(Boolean b) {
1535
1571
* enableDefaultTyping(DefaultTyping.OBJECT_AND_NON_CONCRETE);
1536
1572
*</pre>
1537
1573
*<p>
1538
- * NOTE: use of Default Typing can be a potential security risk if incoming
1539
- * content comes from untrusted sources, and it is recommended that this
1540
- * is either not done, or, if enabled, use {@link #setDefaultTyping}
1541
- * passing a custom {@link TypeResolverBuilder} implementation that white-lists
1542
- * legal types to use.
1574
+ * NOTE: choice of {@link PolymorphicTypeValidator} to pass is critical for security
1575
+ * as allowing all subtypes can be risky for untrusted content.
1576
+ *
1577
+ * @since 2.10
1543
1578
*/
1544
- public ObjectMapper enableDefaultTyping () {
1545
- return enableDefaultTyping (DefaultTyping .OBJECT_AND_NON_CONCRETE );
1579
+ public ObjectMapper enableDefaultTyping (PolymorphicTypeValidator ptv ) {
1580
+ return enableDefaultTyping (ptv , DefaultTyping .OBJECT_AND_NON_CONCRETE );
1546
1581
}
1547
1582
1548
1583
/**
@@ -1551,14 +1586,14 @@ public ObjectMapper enableDefaultTyping() {
1551
1586
* enableDefaultTyping(dti, JsonTypeInfo.As.WRAPPER_ARRAY);
1552
1587
*</pre>
1553
1588
*<p>
1554
- * NOTE: use of Default Typing can be a potential security risk if incoming
1555
- * content comes from untrusted sources, and it is recommended that this
1556
- * is either not done, or, if enabled, use {@link #setDefaultTyping}
1557
- * passing a custom {@link TypeResolverBuilder} implementation that white-lists
1558
- * legal types to use.
1589
+ * NOTE: choice of {@link PolymorphicTypeValidator} to pass is critical for security
1590
+ * as allowing all subtypes can be risky for untrusted content.
1591
+ *
1592
+ * @since 2.10
1559
1593
*/
1560
- public ObjectMapper enableDefaultTyping (DefaultTyping dti ) {
1561
- return enableDefaultTyping (dti , JsonTypeInfo .As .WRAPPER_ARRAY );
1594
+ public ObjectMapper enableDefaultTyping (PolymorphicTypeValidator ptv ,
1595
+ DefaultTyping dti ) {
1596
+ return enableDefaultTyping (ptv , dti , JsonTypeInfo .As .WRAPPER_ARRAY );
1562
1597
}
1563
1598
1564
1599
/**
@@ -1570,26 +1605,24 @@ public ObjectMapper enableDefaultTyping(DefaultTyping dti) {
1570
1605
* and attempts of do so will throw an {@link IllegalArgumentException} to make
1571
1606
* this limitation explicit.
1572
1607
*<p>
1573
- * NOTE: use of Default Typing can be a potential security risk if incoming
1574
- * content comes from untrusted sources, and it is recommended that this
1575
- * is either not done, or, if enabled, use {@link #setDefaultTyping}
1576
- * passing a custom {@link TypeResolverBuilder} implementation that white-lists
1577
- * legal types to use.
1608
+ * NOTE: choice of {@link PolymorphicTypeValidator} to pass is critical for security
1609
+ * as allowing all subtypes can be risky for untrusted content.
1578
1610
*
1579
1611
* @param applicability Defines kinds of types for which additional type information
1580
1612
* is added; see {@link DefaultTyping} for more information.
1613
+ *
1614
+ * @since 2.10
1581
1615
*/
1582
- public ObjectMapper enableDefaultTyping (DefaultTyping applicability , JsonTypeInfo .As includeAs )
1616
+ public ObjectMapper enableDefaultTyping (PolymorphicTypeValidator ptv ,
1617
+ DefaultTyping applicability , JsonTypeInfo .As includeAs )
1583
1618
{
1584
- /* 18-Sep-2014, tatu: Let's add explicit check to ensure no one tries to
1585
- * use "As.EXTERNAL_PROPERTY", since that will not work (with 2.5+)
1586
- */
1619
+ // 18-Sep-2014, tatu: Let's add explicit check to ensure no one tries to
1620
+ // use "As.EXTERNAL_PROPERTY", since that will not work (with 2.5+)
1587
1621
if (includeAs == JsonTypeInfo .As .EXTERNAL_PROPERTY ) {
1588
1622
throw new IllegalArgumentException ("Cannot use includeAs of " +includeAs );
1589
1623
}
1590
1624
1591
- TypeResolverBuilder <?> typer = _constructDefaultTypeResolverBuilder (applicability ,
1592
- getPolymorphicTypeValidator ());
1625
+ TypeResolverBuilder <?> typer = _constructDefaultTypeResolverBuilder (applicability , ptv );
1593
1626
// we'll always use full class name, when using defaulting
1594
1627
typer = typer .init (JsonTypeInfo .Id .CLASS , null );
1595
1628
typer = typer .inclusion (includeAs );
@@ -1604,13 +1637,13 @@ public ObjectMapper enableDefaultTyping(DefaultTyping applicability, JsonTypeInf
1604
1637
* to use for inclusion (default being "@class" since default type information
1605
1638
* always uses class name as type identifier)
1606
1639
*<p>
1607
- * NOTE: use of Default Typing can be a potential security risk if incoming
1608
- * content comes from untrusted sources, and it is recommended that this
1609
- * is either not done, or, if enabled, use {@link #setDefaultTyping}
1610
- * passing a custom {@link TypeResolverBuilder} implementation that white-lists
1611
- * legal types to use.
1640
+ * NOTE: choice of {@link PolymorphicTypeValidator} to pass is critical for security
1641
+ * as allowing all subtypes can be risky for untrusted content.
1642
+ *
1643
+ * @since 2.10
1612
1644
*/
1613
- public ObjectMapper enableDefaultTypingAsProperty (DefaultTyping applicability , String propertyName )
1645
+ public ObjectMapper enableDefaultTypingAsProperty (PolymorphicTypeValidator ptv ,
1646
+ DefaultTyping applicability , String propertyName )
1614
1647
{
1615
1648
TypeResolverBuilder <?> typer = _constructDefaultTypeResolverBuilder (applicability ,
1616
1649
getPolymorphicTypeValidator ());
@@ -1641,7 +1674,7 @@ public ObjectMapper disableDefaultTyping() {
1641
1674
* content comes from untrusted sources, so care should be taken to use
1642
1675
* a {@link TypeResolverBuilder} that can limit allowed classes to
1643
1676
* deserialize.
1644
- *
1677
+ *
1645
1678
* @param typer Type information inclusion handler
1646
1679
*/
1647
1680
public ObjectMapper setDefaultTyping (TypeResolverBuilder <?> typer ) {
@@ -1650,34 +1683,42 @@ public ObjectMapper setDefaultTyping(TypeResolverBuilder<?> typer) {
1650
1683
return this ;
1651
1684
}
1652
1685
1686
+ /*
1687
+ /**********************************************************
1688
+ /* Default typing (automatic polymorphic types): deprecated (pre-2.10)
1689
+ /**********************************************************
1690
+ */
1691
+
1653
1692
/**
1654
- * Method for registering specified class as a subtype, so that
1655
- * typename-based resolution can link supertypes to subtypes
1656
- * (as an alternative to using annotations).
1657
- * Type for given class is determined from appropriate annotation;
1658
- * or if missing, default name (unqualified class name)
1693
+ * @deprecated Since 2.10 use {@link #enableDefaultTyping(PolymorphicTypeValidator)} instead
1659
1694
*/
1660
- public void registerSubtypes (Class <?>... classes ) {
1661
- getSubtypeResolver ().registerSubtypes (classes );
1695
+ @ Deprecated
1696
+ public ObjectMapper enableDefaultTyping () {
1697
+ return enableDefaultTyping (getPolymorphicTypeValidator ());
1662
1698
}
1663
1699
1664
1700
/**
1665
- * Method for registering specified class as a subtype, so that
1666
- * typename-based resolution can link supertypes to subtypes
1667
- * (as an alternative to using annotations).
1668
- * Name may be provided as part of argument, but if not will
1669
- * be based on annotations or use default name (unqualified
1670
- * class name).
1701
+ * @deprecated Since 2.10 use {@link #enableDefaultTyping(PolymorphicTypeValidator,DefaultTyping)} instead
1671
1702
*/
1672
- public void registerSubtypes (NamedType ... types ) {
1673
- getSubtypeResolver ().registerSubtypes (types );
1703
+ @ Deprecated
1704
+ public ObjectMapper enableDefaultTyping (DefaultTyping dti ) {
1705
+ return enableDefaultTyping (dti , JsonTypeInfo .As .WRAPPER_ARRAY );
1674
1706
}
1675
1707
1676
1708
/**
1677
- * @since 2.9
1709
+ * @deprecated Since 2.10 use {@link #enableDefaultTyping(PolymorphicTypeValidator,DefaultTyping,JsonTypeInfo.As)} instead
1678
1710
*/
1679
- public void registerSubtypes (Collection <Class <?>> subtypes ) {
1680
- getSubtypeResolver ().registerSubtypes (subtypes );
1711
+ @ Deprecated
1712
+ public ObjectMapper enableDefaultTyping (DefaultTyping applicability , JsonTypeInfo .As includeAs ) {
1713
+ return enableDefaultTyping (getPolymorphicTypeValidator (), applicability , includeAs );
1714
+ }
1715
+
1716
+ /**
1717
+ * @deprecated Since 2.10 use {@link #enableDefaultTypingAsProperty(PolymorphicTypeValidator,DefaultTyping,String)} instead
1718
+ */
1719
+ @ Deprecated
1720
+ public ObjectMapper enableDefaultTypingAsProperty (DefaultTyping applicability , String propertyName ) {
1721
+ return enableDefaultTypingAsProperty (getPolymorphicTypeValidator (), applicability , propertyName );
1681
1722
}
1682
1723
1683
1724
/*
0 commit comments