Skip to content

Commit

Permalink
Simplify property/accessor massaging due to later (and more accurate)…
Browse files Browse the repository at this point in the history
… merging of annotations
  • Loading branch information
cowtowncoder committed Sep 26, 2017
1 parent 5ad1371 commit 8453b03
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,9 @@ protected void collectAll()
_removeUnwantedAccessor(props);
// Rename remaining properties
_renameProperties(props);
// then merge annotations, to simplify further processing

// then merge annotations, to simplify further processing: has to be done AFTER
// preceding renaming step to get right propagation
for (POJOPropertyBuilder property : props.values()) {
property.mergeAnnotations(_forSerialization);
}
Expand All @@ -311,17 +313,15 @@ protected void collectAll()
_renameUsing(props, naming);
}

/* Sort by visibility (explicit over implicit); drop all but first
* of member type (getter, setter etc) if there is visibility
* difference
*/
// Sort by visibility (explicit over implicit); drop all but first
// of member type (getter, setter etc) if there is visibility
// difference
for (POJOPropertyBuilder property : props.values()) {
property.trimByVisibility();
}

/* and, if required, apply wrapper name: note, MUST be done after
* annotations are merged.
*/
// and, if required, apply wrapper name: note, MUST be done after
// annotations are merged.
if (_config.isEnabled(MapperFeature.USE_WRAPPER_NAME_AS_PROPERTY_NAME)) {
_renameWithWrappers(props);
}
Expand All @@ -337,7 +337,7 @@ protected void collectAll()
/* Overridable internal methods, adding members
/**********************************************************
*/

/**
* Method for collecting basic information on all fields found
*/
Expand Down Expand Up @@ -450,9 +450,6 @@ protected void _addCreators(Map<String, POJOPropertyBuilder> props)
}
}

/**
* @since 2.4
*/
protected void _addCreatorParam(Map<String, POJOPropertyBuilder> props,
AnnotatedParameter param)
{
Expand Down Expand Up @@ -840,9 +837,7 @@ protected void _renameUsing(Map<String, POJOPropertyBuilder> propMap,
} else {
simpleName = fullName.getSimpleName();
}
/* As per [JACKSON-687], need to consider case where there may already be
* something in there...
*/
// Need to consider case where there may already be something in there...
POJOPropertyBuilder old = propMap.get(simpleName);
if (old == null) {
propMap.put(simpleName, prop);
Expand Down Expand Up @@ -903,8 +898,8 @@ protected void _renameWithWrappers(Map<String, POJOPropertyBuilder> props)
/**********************************************************
*/

/* First, order by [JACKSON-90] (explicit ordering and/or alphabetic)
* and then for [JACKSON-170] (implicitly order creator properties before others)
/* First, explicit ordering and/or alphabetic
* and then implicitly order creator properties before others.
*/
protected void _sortProperties(Map<String, POJOPropertyBuilder> props)
{
Expand Down Expand Up @@ -1036,9 +1031,8 @@ private PropertyNamingStrategy _findNamingStrategy()
if (namingDef instanceof PropertyNamingStrategy) {
return (PropertyNamingStrategy) namingDef;
}
/* Alas, there's no way to force return type of "either class
* X or Y" -- need to throw an exception after the fact
*/
// Alas, there's no way to force return type of "either class
// X or Y" -- need to throw an exception after the fact
if (!(namingDef instanceof Class)) {
throw new IllegalStateException("AnnotationIntrospector returned PropertyNamingStrategy definition of type "
+namingDef.getClass().getName()+"; expected type PropertyNamingStrategy or Class<PropertyNamingStrategy> instead");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ protected POJOPropertyBuilder(MapperConfig<?> config, AnnotationIntrospector ai,
_forSerialization = forSerialization;
}

// protected since 2.9 (was public before)
protected POJOPropertyBuilder(POJOPropertyBuilder src, PropertyName newName)
{
_config = src._config;
Expand Down Expand Up @@ -134,9 +133,7 @@ public int compareTo(POJOPropertyBuilder other)
} else if (other._ctorParameters != null) {
return 1;
}
/* otherwise sort by external name (including sorting of
* ctor parameters)
*/
// otherwise sort by external name (including sorting of ctor parameters)
return getName().compareTo(other.getName());
}

Expand Down Expand Up @@ -172,7 +169,7 @@ public PropertyName getWrapperName() {
* occur, try commenting out full traversal code
*/
AnnotatedMember member = getPrimaryMember();
return (member == null || _annotationIntrospector == null) ? null
return (member == null) ? null
: _annotationIntrospector.findWrapperName(member);
/*
return fromMemberAnnotations(new WithMember<PropertyName>() {
Expand Down Expand Up @@ -605,12 +602,7 @@ protected int _setterPriority(AnnotatedMethod m)

@Override
public Class<?>[] findViews() {
return fromMemberAnnotations(new WithMember<Class<?>[]>() {
@Override
public Class<?>[] withMember(AnnotatedMember member) {
return _annotationIntrospector.findViews(member);
}
});
return _annotationIntrospector.findViews(getPrimaryMember());
}

@Override
Expand All @@ -624,75 +616,58 @@ public AnnotationIntrospector.ReferenceProperty findReferenceType() {
}
return result;
}
result = fromMemberAnnotations(new WithMember<AnnotationIntrospector.ReferenceProperty>() {
@Override
public AnnotationIntrospector.ReferenceProperty withMember(AnnotatedMember member) {
return _annotationIntrospector.findReferenceType(member);
}
});
AnnotatedMember m = getPrimaryMember();
result = (m == null) ? null : _annotationIntrospector.findReferenceType(m);
_referenceInfo = (result == null) ? NOT_REFEFERENCE_PROP : result;
return result;
}

@Override
public boolean isTypeId() {
Boolean b = fromMemberAnnotations(new WithMember<Boolean>() {
@Override
public Boolean withMember(AnnotatedMember member) {
return _annotationIntrospector.isTypeId(member);
AnnotatedMember m = getPrimaryMember();
if (m != null) {
Boolean b = _annotationIntrospector.isTypeId(m);
if (b != null) {
return b.booleanValue();
}
});
return (b != null) && b.booleanValue();
}
return false;
}

protected Boolean _findRequired() {
return fromMemberAnnotations(new WithMember<Boolean>() {
@Override
public Boolean withMember(AnnotatedMember member) {
return _annotationIntrospector.hasRequiredMarker(member);
}
});
AnnotatedMember m = getPrimaryMember();
return (m == null) ? null
: _annotationIntrospector.hasRequiredMarker(m);
}

protected String _findDescription() {
return fromMemberAnnotations(new WithMember<String>() {
@Override
public String withMember(AnnotatedMember member) {
return _annotationIntrospector.findPropertyDescription(member);
}
});
AnnotatedMember m = getPrimaryMember();
return (m == null) ? null
: _annotationIntrospector.findPropertyDescription(m);
}

protected Integer _findIndex() {
return fromMemberAnnotations(new WithMember<Integer>() {
@Override
public Integer withMember(AnnotatedMember member) {
return _annotationIntrospector.findPropertyIndex(member);
}
});
AnnotatedMember m = getPrimaryMember();
return (m == null) ? null
: _annotationIntrospector.findPropertyIndex(m);
}

protected String _findDefaultValue() {
return fromMemberAnnotations(new WithMember<String>() {
@Override
public String withMember(AnnotatedMember member) {
return _annotationIntrospector.findPropertyDefaultValue(member);
}
});
AnnotatedMember m = getPrimaryMember();
return (m == null) ? null
: _annotationIntrospector.findPropertyDefaultValue(m);
}

@Override
public ObjectIdInfo findObjectIdInfo() {
return fromMemberAnnotations(new WithMember<ObjectIdInfo>() {
@Override
public ObjectIdInfo withMember(AnnotatedMember member) {
ObjectIdInfo info = _annotationIntrospector.findObjectIdInfo(member);
if (info != null) {
info = _annotationIntrospector.findObjectReferenceInfo(member, info);
}
return info;
AnnotatedMember m = getPrimaryMember();
if (m != null) {
ObjectIdInfo info = _annotationIntrospector.findObjectIdInfo(m);
if (info != null) {
return _annotationIntrospector.findObjectReferenceInfo(m, info);
}
});
}
return null;
}

@Override
Expand All @@ -702,12 +677,13 @@ public JsonInclude.Value findInclusion() {
// 17-Aug-2016, tatu: Do NOT include global, or per-type defaults, because
// not all of this information (specifically, enclosing type's settings)
// is available here
JsonInclude.Value v = (_annotationIntrospector == null) ?
null : _annotationIntrospector.findPropertyInclusion(a);
JsonInclude.Value v = _annotationIntrospector.findPropertyInclusion(a);
return (v == null) ? JsonInclude.Value.empty() : v;
}

public JsonProperty.Access findAccess() {
// 25-Sep-2017, tatu: IMPORTANT! Called BEFORE merge occurs so MUST traverse
// accessors separately
return fromMemberAnnotationsExcept(new WithMember<JsonProperty.Access>() {
@Override
public JsonProperty.Access withMember(AnnotatedMember member) {
Expand Down Expand Up @@ -1156,10 +1132,6 @@ protected <T> T fromMemberAnnotations(WithMember<T> func)

protected <T> T fromMemberAnnotationsExcept(WithMember<T> func, T defaultValue)
{
if (_annotationIntrospector == null) {
return null;
}

// NOTE: here we must ask ALL accessors, but the order varies between
// serialization, deserialization
if (_forSerialization) {
Expand Down

0 comments on commit 8453b03

Please sign in to comment.