diff --git a/release-notes/VERSION b/release-notes/VERSION index a7269812e7..c0fbf662a9 100644 --- a/release-notes/VERSION +++ b/release-notes/VERSION @@ -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) diff --git a/src/main/java/com/fasterxml/jackson/databind/AnnotationIntrospector.java b/src/main/java/com/fasterxml/jackson/databind/AnnotationIntrospector.java index 2d315206c7..5e1721cb3b 100644 --- a/src/main/java/com/fasterxml/jackson/databind/AnnotationIntrospector.java +++ b/src/main/java/com/fasterxml/jackson/databind/AnnotationIntrospector.java @@ -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. diff --git a/src/main/java/com/fasterxml/jackson/databind/introspect/AnnotationIntrospectorPair.java b/src/main/java/com/fasterxml/jackson/databind/introspect/AnnotationIntrospectorPair.java index 0428cd5592..0a7b8d5826 100644 --- a/src/main/java/com/fasterxml/jackson/databind/introspect/AnnotationIntrospectorPair.java +++ b/src/main/java/com/fasterxml/jackson/databind/introspect/AnnotationIntrospectorPair.java @@ -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); diff --git a/src/main/java/com/fasterxml/jackson/databind/introspect/JacksonAnnotationIntrospector.java b/src/main/java/com/fasterxml/jackson/databind/introspect/JacksonAnnotationIntrospector.java index 0fb0d6aa7a..301e9aa2ea 100644 --- a/src/main/java/com/fasterxml/jackson/databind/introspect/JacksonAnnotationIntrospector.java +++ b/src/main/java/com/fasterxml/jackson/databind/introspect/JacksonAnnotationIntrospector.java @@ -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 diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/PropertyBuilder.java b/src/main/java/com/fasterxml/jackson/databind/ser/PropertyBuilder.java index 689fced871..ef82ade3b7 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/PropertyBuilder.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/PropertyBuilder.java @@ -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,