Skip to content

Commit

Permalink
Fix #840
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Jun 24, 2015
1 parent 5ba0146 commit 51c3f7c
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 59 deletions.
1 change: 1 addition & 0 deletions release-notes/VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ Project: jackson-databind
(reported by mjr6140@gitgub)
#828: Respect DeserializationFeatures.WRAP_EXCEPTIONS in CollectionDeserializer
(contributed by Steve G, thezerobit@github)
#840: Change semantics of `@JsonPropertyOrder(alphabetic)` to only count `true` value
- Remove old cglib compatibility tests; cause problems in Eclipse

2.5.4 (09-Jun-2015)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -765,11 +765,6 @@ public Boolean findSerializationSortAlphabetically(Annotated ann) {
return null;
}

@Deprecated // since 2.4
public Boolean findSerializationSortAlphabetically(AnnotatedClass ac) {
return null;
}

/**
* Method for adding possible virtual properties to be serialized along
* with regular properties.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -488,18 +488,6 @@ public String[] findSerializationPropertyOrder(AnnotatedClass ac) {
return (r == null) ? _secondary.findSerializationPropertyOrder(ac) : r;
}

/**
* Method for checking whether an annotation indicates that serialized properties
* for which no explicit is defined should be alphabetically (lexicograpically)
* ordered
*/
@Override
@Deprecated
public Boolean findSerializationSortAlphabetically(AnnotatedClass ac) {
Boolean r = _primary.findSerializationSortAlphabetically(ac);
return (r == null) ? _secondary.findSerializationSortAlphabetically(ac) : r;
}

@Override
public Boolean findSerializationSortAlphabetically(Annotated ann) {
Boolean r = _primary.findSerializationSortAlphabetically(ann);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -616,15 +616,15 @@ public Boolean findSerializationSortAlphabetically(Annotated ann) {
return _findSortAlpha(ann);
}

@Override
@Deprecated
public Boolean findSerializationSortAlphabetically(AnnotatedClass ac) {
return _findSortAlpha(ac);
}

private final Boolean _findSortAlpha(Annotated ann) {
JsonPropertyOrder order = _findAnnotation(ann, JsonPropertyOrder.class);
return (order == null) ? null : order.alphabetic();
/* 23-Jun-2015, tatu: as per [databind#840], let's only consider
* `true` to have any significance.
*/
if ((order != null) && order.alphabetic()) {
return Boolean.TRUE;
}
return null;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,47 +93,49 @@ protected BeanPropertyWriter buildWriter(SerializerProvider prov,
boolean suppressNulls = false;

JsonInclude.Include inclusion = propDef.findInclusion();
if (inclusion == null) {
if ((inclusion == null)
|| (inclusion == JsonInclude.Include.USE_DEFAULTS)) { // since 2.6
inclusion = _defaultInclusion;
if (inclusion == null) {
inclusion = JsonInclude.Include.ALWAYS;
}
}
if (inclusion != null) {
switch (inclusion) {
case NON_DEFAULT:
valueToSuppress = getDefaultValue(propDef.getName(), am);
if (valueToSuppress == null) {
suppressNulls = true;
} else {
// [JACKSON-531]: Allow comparison of arrays too...
if (valueToSuppress.getClass().isArray()) {
valueToSuppress = ArrayBuilders.getArrayComparator(valueToSuppress);
}
}
break;
case NON_ABSENT: // new with 2.6, to support Guava/JDK8 Optionals
// always suppress nulls
switch (inclusion) {
case NON_DEFAULT:
valueToSuppress = getDefaultValue(propDef.getName(), am);
if (valueToSuppress == null) {
suppressNulls = true;
// and for referential types, also "empty", which in their case means "absent"
if (declaredType.isReferenceType()) {
valueToSuppress = BeanPropertyWriter.MARKER_FOR_EMPTY;
} else {
if (valueToSuppress.getClass().isArray()) {
valueToSuppress = ArrayBuilders.getArrayComparator(valueToSuppress);
}
break;
case NON_EMPTY:
// always suppress nulls
suppressNulls = true;
// but possibly also 'empty' values:
}
break;
case NON_ABSENT: // new with 2.6, to support Guava/JDK8 Optionals
// always suppress nulls
suppressNulls = true;
// and for referential types, also "empty", which in their case means "absent"
if (declaredType.isReferenceType()) {
valueToSuppress = BeanPropertyWriter.MARKER_FOR_EMPTY;
}
break;
case NON_EMPTY:
// always suppress nulls
suppressNulls = true;
// but possibly also 'empty' values:
valueToSuppress = BeanPropertyWriter.MARKER_FOR_EMPTY;
break;
case NON_NULL:
suppressNulls = true;
// fall through
case ALWAYS: // default
default:
// we may still want to suppress empty collections, as per [JACKSON-254]:
if (declaredType.isContainerType()
&& !_config.isEnabled(SerializationFeature.WRITE_EMPTY_JSON_ARRAYS)) {
valueToSuppress = BeanPropertyWriter.MARKER_FOR_EMPTY;
break;
case NON_NULL:
suppressNulls = true;
// fall through
case ALWAYS: // default
// we may still want to suppress empty collections, as per [JACKSON-254]:
if (declaredType.isContainerType()
&& !_config.isEnabled(SerializationFeature.WRITE_EMPTY_JSON_ARRAYS)) {
valueToSuppress = BeanPropertyWriter.MARKER_FOR_EMPTY;
}
break;
}
break;
}
BeanPropertyWriter bpw = new BeanPropertyWriter(propDef,
am, _beanDesc.getClassAnnotations(), declaredType,
Expand Down

0 comments on commit 51c3f7c

Please sign in to comment.