1
1
package com .fasterxml .jackson .module .jaxb ;
2
2
3
- import java .beans .Introspector ;
4
3
import java .lang .annotation .Annotation ;
5
4
import java .lang .reflect .*;
6
5
import java .util .*;
19
18
import com .fasterxml .jackson .databind .jsontype .TypeResolverBuilder ;
20
19
import com .fasterxml .jackson .databind .jsontype .impl .StdTypeResolverBuilder ;
21
20
import com .fasterxml .jackson .databind .type .TypeFactory ;
22
- import com .fasterxml .jackson .databind .util .BeanUtil ;
23
21
import com .fasterxml .jackson .databind .util .ClassUtil ;
24
22
import com .fasterxml .jackson .databind .util .Converter ;
25
23
import com .fasterxml .jackson .module .jaxb .deser .DataHandlerJsonDeserializer ;
@@ -307,11 +305,11 @@ public ObjectIdInfo findObjectIdInfo(Annotated ann)
307
305
switch (m .getParameterCount ()) {
308
306
case 0 : // getter
309
307
idPropName = findJaxbPropertyName (m , m .getRawType (),
310
- okNameForGetter (m ));
308
+ _okNameForGetter (m ));
311
309
break method_loop ;
312
310
case 1 : // setter
313
311
idPropName = findJaxbPropertyName (m , m .getRawType (),
314
- okNameForMutator (m ));
312
+ _okNameForMutator (m ));
315
313
break method_loop ;
316
314
}
317
315
}
@@ -451,9 +449,9 @@ public PropertyName findWrapperName(Annotated ann)
451
449
AnnotatedMethod am = (AnnotatedMethod ) ann ;
452
450
String str ;
453
451
if (am .getParameterCount () == 0 ) {
454
- str = okNameForGetter (am );
452
+ str = _okNameForGetter (am );
455
453
} else {
456
- str = okNameForMutator (am );
454
+ str = _okNameForMutator (am );
457
455
}
458
456
if (str != null ) {
459
457
return name .withSimpleName (str );
@@ -648,7 +646,7 @@ public List<NamedType> findSubtypes(Annotated a)
648
646
}
649
647
}
650
648
if (name == null || MARKER_FOR_DEFAULT .equals (name )) {
651
- name = Introspector . decapitalize (refType .getSimpleName ());
649
+ name = _decapitalize (refType .getSimpleName ());
652
650
}
653
651
result .add (new NamedType (refType , name ));
654
652
}
@@ -921,7 +919,7 @@ public PropertyName findNameForSerialization(Annotated a)
921
919
if (a instanceof AnnotatedMethod ) {
922
920
AnnotatedMethod am = (AnnotatedMethod ) a ;
923
921
return isVisible (am )
924
- ? findJaxbPropertyName (am , am .getRawType (), okNameForGetter (am ))
922
+ ? findJaxbPropertyName (am , am .getRawType (), _okNameForGetter (am ))
925
923
: null ;
926
924
}
927
925
if (a instanceof AnnotatedField ) {
@@ -1118,7 +1116,7 @@ public PropertyName findNameForDeserialization(Annotated a)
1118
1116
return null ;
1119
1117
}
1120
1118
Class <?> rawType = am .getRawParameterType (0 );
1121
- return findJaxbPropertyName (am , rawType , okNameForMutator (am ));
1119
+ return findJaxbPropertyName (am , rawType , _okNameForMutator (am ));
1122
1120
}
1123
1121
if (a instanceof AnnotatedField ) {
1124
1122
AnnotatedField af = (AnnotatedField ) a ;
@@ -1333,7 +1331,7 @@ private PropertyName findJaxbPropertyName(Annotated ae, Class<?> aeType, String
1333
1331
return _combineNames (name , rootElement .namespace (), defaultName );
1334
1332
}
1335
1333
// Is there a namespace there to use? Probably not?
1336
- return new PropertyName (Introspector . decapitalize (aeType .getSimpleName ()));
1334
+ return new PropertyName (_decapitalize (aeType .getSimpleName ()));
1337
1335
}
1338
1336
}
1339
1337
}
@@ -1577,29 +1575,29 @@ protected Class<?> _getTypeFromXmlElement(Annotated a) {
1577
1575
/**********************************************************
1578
1576
*/
1579
1577
1580
- protected String okNameForGetter (AnnotatedMethod am ) {
1578
+ protected String _okNameForGetter (AnnotatedMethod am ) {
1581
1579
final String name = am .getName ();
1582
1580
if (name .startsWith ("is" )) { // plus, must return a boolean
1583
1581
Class <?> rt = am .getRawType ();
1584
1582
if (rt == Boolean .class || rt == Boolean .TYPE ) {
1585
- return stdManglePropertyName (name , 2 );
1583
+ return _stdManglePropertyName (name , 2 );
1586
1584
}
1587
1585
}
1588
1586
if (name .startsWith ("get" )) {
1589
- return stdManglePropertyName (name , 3 );
1587
+ return _stdManglePropertyName (name , 3 );
1590
1588
}
1591
1589
return null ;
1592
1590
}
1593
1591
1594
- protected String okNameForMutator (AnnotatedMethod am ) {
1592
+ protected String _okNameForMutator (AnnotatedMethod am ) {
1595
1593
final String name = am .getName ();
1596
1594
if (name .startsWith ("set" )) {
1597
- return stdManglePropertyName (name , 3 );
1595
+ return _stdManglePropertyName (name , 3 );
1598
1596
}
1599
1597
return null ;
1600
1598
}
1601
1599
1602
- protected String stdManglePropertyName (final String basename , final int offset )
1600
+ protected String _stdManglePropertyName (final String basename , final int offset )
1603
1601
{
1604
1602
final int end = basename .length ();
1605
1603
if (end == offset ) { // empty name, nope
@@ -1625,4 +1623,27 @@ protected String stdManglePropertyName(final String basename, final int offset)
1625
1623
return sb .toString ();
1626
1624
}
1627
1625
1626
+ // 02-Nov-2020, tatu: Does not seem to be covered by any unit tests that
1627
+ // fail if we simply returned "name" as-is.... ?!
1628
+ // @since 2.12: to remove `java.beans.Introspector.decapitalize(...)` dependency
1629
+ protected String _decapitalize (String name ) {
1630
+ if (name .length () > 0 ) {
1631
+ final char firstOrig = name .charAt (0 );
1632
+ final char firstLC = Character .toLowerCase (firstOrig );
1633
+
1634
+ // Lower-case first character if not already lower-case and
1635
+ // is not followed by another upper-case character
1636
+ if (firstOrig != firstLC ) {
1637
+ if (name .length () == 1 ) {
1638
+ return String .valueOf (firstLC );
1639
+ }
1640
+ if (!Character .isUpperCase (name .charAt (1 ))) {
1641
+ char chars [] = name .toCharArray ();
1642
+ chars [0 ] = Character .toLowerCase (chars [0 ]);
1643
+ return new String (chars );
1644
+ }
1645
+ }
1646
+ }
1647
+ return name ;
1648
+ }
1628
1649
}
0 commit comments