Skip to content

Commit

Permalink
Fix #1327
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Aug 18, 2016
1 parent 84d6872 commit 61a829a
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,20 @@ public JsonInclude.Value getDefaultPropertyInclusion(Class<?> baseType) {
return EMPTY_INCLUDE;
}

@Override
public JsonInclude.Value getDefaultPropertyInclusion(Class<?> baseType,
JsonInclude.Value defaultIncl)
{
ConfigOverride overrides = findConfigOverride(baseType);
if (overrides != null) {
JsonInclude.Value v = overrides.getInclude();
if (v != null) {
return v;
}
}
return defaultIncl;
}

/*
/**********************************************************
/* MapperConfig implementation/overrides: other
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,20 @@ public JsonInclude.Value getDefaultPropertyInclusion(Class<?> baseType) {
return _serializationInclusion;
}

@Override
public JsonInclude.Value getDefaultPropertyInclusion(Class<?> baseType,
JsonInclude.Value defaultIncl)
{
ConfigOverride overrides = findConfigOverride(baseType);
if (overrides != null) {
JsonInclude.Value v = overrides.getInclude();
if (v != null) {
return v;
}
}
return defaultIncl;
}

/*
/**********************************************************
/* Configuration: other
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,12 +357,26 @@ public BeanDescription introspectDirectClassAnnotations(Class<?> cls) {

/**
* Accessor for default property inclusion to use for serialization,
* considering possible per-type override for given base type.
* considering possible per-type override for given base type.<br>
* NOTE: if no override found, defaults to value returned by
* {@link #getDefaultPropertyInclusion()}.
*
* @since 2.7
*/
public abstract JsonInclude.Value getDefaultPropertyInclusion(Class<?> baseType);

/**
* Accessor for default property inclusion to use for serialization,
* considering possible per-type override for given base type; but
* if none found, returning given <code>defaultIncl</code>
*
* @param defaultIncl Inclusion setting to return if no overrides found.
*
* @since 2.8.2
*/
public abstract JsonInclude.Value getDefaultPropertyInclusion(Class<?> baseType,
JsonInclude.Value defaultIncl);

/**
* Accessor for default format settings to use for serialization (and, to a degree
* deserialization), considering baseline settings and per-type defaults
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,8 @@ public JsonInclude.Value findPropertyInclusion(JsonInclude.Value defValue) {
if (_annotationIntrospector != null) {
JsonInclude.Value incl = _annotationIntrospector.findPropertyInclusion(_classInfo);
if (incl != null) {
return defValue.withOverrides(incl);
return (defValue == null) ? incl
: defValue.withOverrides(incl);
}
}
return defValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,8 @@ public boolean isRequired() {
/**
* Method used to check if this property has specific inclusion override
* associated with it or not.
* It should NOT check for any default settings (global, per-type, or
* containing POJO settings)
*
* @since 2.5
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -553,17 +553,11 @@ public ObjectIdInfo withMember(AnnotatedMember member) {
public JsonInclude.Value findInclusion() {
AnnotatedMember a = getAccessor();
// 16-Apr-2106, tatu: Let's include per-type default inclusion too
JsonInclude.Value v = _config.getDefaultPropertyInclusion(a.getRawType());
if (_annotationIntrospector != null) {
JsonInclude.Value v2 = _annotationIntrospector.findPropertyInclusion(a);
if (v2 != null) {
if (v == null) {
v = v2;
} else {
v = v.withOverrides(v2);
}
}
}
// 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);
return (v == null) ? JsonInclude.Value.empty() : v;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ public PropertyBuilder(SerializationConfig config, BeanDescription beanDesc)
{
_config = config;
_beanDesc = beanDesc;
// NOTE: this includes global defaults and defaults of POJO that contains property,
// but not defaults for types of properties referenced
_defaultInclusion = beanDesc.findPropertyInclusion(
config.getDefaultPropertyInclusion(beanDesc.getBeanClass()));
_annotationIntrospector = _config.getAnnotationIntrospector();
Expand Down Expand Up @@ -97,14 +99,23 @@ protected BeanPropertyWriter buildWriter(SerializerProvider prov,
Object valueToSuppress = null;
boolean suppressNulls = false;

JsonInclude.Value inclV = _defaultInclusion.withOverrides(propDef.findInclusion());
// 12-Jul-2016, tatu: [databind#1256] Need to make sure we consider type refinement
JavaType actualType = (serializationType == null) ? declaredType : serializationType;

// 17-Aug-2016, tatu: Default inclusion covers global default (for all types), as well
// as type-default for enclosing POJO. What we need, then, is per-type default (if any)
// for declared property type... and finally property annotation overrides
JsonInclude.Value inclV = _config.getDefaultPropertyInclusion(actualType.getRawClass(),
_defaultInclusion);

// property annotation override

inclV = inclV.withOverrides(propDef.findInclusion());
JsonInclude.Include inclusion = inclV.getValueInclusion();

if (inclusion == JsonInclude.Include.USE_DEFAULTS) { // should not occur but...
inclusion = JsonInclude.Include.ALWAYS;
}

// 12-Jul-2016, tatu: [databind#1256] Need to make sure we consider type refinement
JavaType actualType = (serializationType == null) ? declaredType : serializationType;

switch (inclusion) {
case NON_DEFAULT:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.fasterxml.jackson.failing;
package com.fasterxml.jackson.databind.filter;

import java.util.*;

Expand Down

0 comments on commit 61a829a

Please sign in to comment.