Skip to content

Commit 54fb5a3

Browse files
committed
Start work to support aliases
1 parent 310f35c commit 54fb5a3

File tree

5 files changed

+43
-12
lines changed

5 files changed

+43
-12
lines changed

src/main/java/com/fasterxml/jackson/databind/AnnotationIntrospector.java

+11-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public enum Type {
6262
* {@link com.fasterxml.jackson.annotation.JsonManagedReference}
6363
*/
6464
MANAGED_REFERENCE
65-
65+
6666
/**
6767
* Reference property that Jackson manages by suppressing it during serialization,
6868
* and reconstructing during deserialization.
@@ -570,6 +570,16 @@ public JsonFormat.Value findFormat(Annotated memberOrClass) {
570570
*/
571571
public String findImplicitPropertyName(AnnotatedMember member) { return null; }
572572

573+
/**
574+
* Method called to find if given property has alias(es) defined.
575+
*
576+
* @return `null` if member has no information; otherwise a `List` (possibly
577+
* empty) of aliases to use.
578+
*
579+
* @since 2.9
580+
*/
581+
public List<PropertyName> findPropertyAliases(Annotated ann) { return null; }
582+
573583
/**
574584
* Method for finding optional access definition for a property, annotated
575585
* on one of its accessors. If a definition for read-only, write-only

src/main/java/com/fasterxml/jackson/databind/MapperFeature.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ public enum MapperFeature implements ConfigFeature
433433
* @since 2.9
434434
*/
435435
IGNORE_MERGE_FOR_UNMERGEABLE(true)
436-
436+
437437
;
438438

439439
private final boolean _defaultState;

src/main/java/com/fasterxml/jackson/databind/introspect/AnnotationIntrospectorPair.java

+9-3
Original file line numberDiff line numberDiff line change
@@ -465,9 +465,15 @@ public Integer findPropertyIndex(Annotated ann) {
465465
}
466466

467467
@Override
468-
public String findImplicitPropertyName(AnnotatedMember param) {
469-
String r = _primary.findImplicitPropertyName(param);
470-
return (r == null) ? _secondary.findImplicitPropertyName(param) : r;
468+
public String findImplicitPropertyName(AnnotatedMember ann) {
469+
String r = _primary.findImplicitPropertyName(ann);
470+
return (r == null) ? _secondary.findImplicitPropertyName(ann) : r;
471+
}
472+
473+
@Override
474+
public List<PropertyName> findPropertyAliases(Annotated ann) {
475+
List<PropertyName> r = _primary.findPropertyAliases(ann);
476+
return (r == null) ? _secondary.findPropertyAliases(ann) : r;
471477
}
472478

473479
@Override

src/main/java/com/fasterxml/jackson/databind/introspect/JacksonAnnotationIntrospector.java

+19-1
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,25 @@ public String findImplicitPropertyName(AnnotatedMember m) {
335335
PropertyName n = _findConstructorName(m);
336336
return (n == null) ? null : n.getSimpleName();
337337
}
338-
338+
339+
@Override
340+
public List<PropertyName> findPropertyAliases(Annotated m) {
341+
JsonAlias ann = _findAnnotation(m, JsonAlias.class);
342+
if (ann == null) {
343+
return null;
344+
}
345+
String[] strs = ann.value();
346+
final int len = strs.length;
347+
if (len == 0) {
348+
return Collections.emptyList();
349+
}
350+
List<PropertyName> result = new ArrayList<>(len);
351+
for (int i = 0; i < len; ++i) {
352+
result.add(PropertyName.construct(strs[i]));
353+
}
354+
return result;
355+
}
356+
339357
@Override
340358
public boolean hasIgnoreMarker(AnnotatedMember m) {
341359
return _isIgnorable(m);

src/main/java/com/fasterxml/jackson/databind/introspect/POJOPropertiesCollector.java

+3-6
Original file line numberDiff line numberDiff line change
@@ -502,10 +502,8 @@ protected void _addCreatorParam(Map<String, POJOPropertyBuilder> props,
502502
boolean expl = (pn != null && !pn.isEmpty());
503503
if (!expl) {
504504
if (impl.isEmpty()) {
505-
/* Important: if neither implicit nor explicit name, can not make use
506-
* of this creator parameter -- may or may not be a problem, verified
507-
* at a later point.
508-
*/
505+
// Important: if neither implicit nor explicit name, can not make use of
506+
// this creator parameter -- may or may not be a problem, verified at a later point.
509507
return;
510508
}
511509
// Also: if this occurs, there MUST be explicit annotation on creator itself
@@ -529,14 +527,13 @@ protected void _addCreatorParam(Map<String, POJOPropertyBuilder> props,
529527
prop.addCtor(param, pn, expl, true, false);
530528
_creatorProperties.add(prop);
531529
}
532-
530+
533531
/**
534532
* Method for collecting basic information on all fields found
535533
*/
536534
protected void _addMethods(Map<String, POJOPropertyBuilder> props)
537535
{
538536
final AnnotationIntrospector ai = _annotationIntrospector;
539-
540537
for (AnnotatedMethod m : _classDef.memberMethods()) {
541538
/* For methods, handling differs between getters and setters; and
542539
* we will also only consider entries that either follow the bean

0 commit comments

Comments
 (0)