Piping view definitions through
diff --git a/src/main/java/com/fasterxml/jackson/databind/BeanPropertyDefinition.java b/src/main/java/com/fasterxml/jackson/databind/BeanPropertyDefinition.java
index 31dbdf6..de126cf 100644
--- a/src/main/java/com/fasterxml/jackson/databind/BeanPropertyDefinition.java
+++ b/src/main/java/com/fasterxml/jackson/databind/BeanPropertyDefinition.java
@@ -42,7 +42,7 @@
public boolean couldSerialize() {
return getAccessor() != null;
}
-
+
public abstract AnnotatedMethod getGetter();
public abstract AnnotatedMethod getSetter();
public abstract AnnotatedField getField();
@@ -61,4 +61,9 @@
* Null if no such member exists.
*/
public abstract AnnotatedMember getMutator();
+
+ /**
+ * Method used to find View-inclusion definitions for the property.
+ */
+ public abstract Class<?>[] getViews();
}
diff --git a/src/main/java/com/fasterxml/jackson/databind/introspect/POJOPropertiesCollector.java b/src/main/java/com/fasterxml/jackson/databind/introspect/POJOPropertiesCollector.java
index 080392b..3de38d2 100644
--- a/src/main/java/com/fasterxml/jackson/databind/introspect/POJOPropertiesCollector.java
+++ b/src/main/java/com/fasterxml/jackson/databind/introspect/POJOPropertiesCollector.java
@@ -233,7 +233,7 @@
/*
/**********************************************************
- /* Overridable internal methods, sorting
+ /* Overridable internal methods, sorting, other stuff
/**********************************************************
*/
@@ -243,16 +243,16 @@
protected void _sortProperties()
{
// Then how about explicit ordering?
- AnnotationIntrospector intr = _config.getAnnotationIntrospector();
+ AnnotationIntrospector intr = _annotationIntrospector;
boolean sort;
- Boolean alpha = intr.findSerializationSortAlphabetically(_classDef);
+ Boolean alpha = (intr == null) ? null : intr.findSerializationSortAlphabetically(_classDef);
if (alpha == null) {
sort = _config.shouldSortPropertiesAlphabetically();
} else {
sort = alpha.booleanValue();
}
- String[] propertyOrder = intr.findSerializationPropertyOrder(_classDef);
+ String[] propertyOrder = (intr == null) ? null : intr.findSerializationPropertyOrder(_classDef);
// no sorting? no need to shuffle, then
if (!sort && (_creatorProperties == null) && (propertyOrder == null)) {
@@ -302,7 +302,7 @@
_properties.clear();
_properties.putAll(ordered);
}
-
+
/*
/**********************************************************
/* Overridable internal methods, adding members
@@ -673,7 +673,8 @@
{
POJOPropertyBuilder prop = _properties.get(implName);
if (prop == null) {
- prop = new POJOPropertyBuilder(implName);
+ prop = new POJOPropertyBuilder(implName, _annotationIntrospector,
+ _forSerialization);
_properties.put(implName, prop);
}
return prop;
diff --git a/src/main/java/com/fasterxml/jackson/databind/introspect/POJOPropertyBuilder.java b/src/main/java/com/fasterxml/jackson/databind/introspect/POJOPropertyBuilder.java
index 0b46f0b..2ac3c08 100644
--- a/src/main/java/com/fasterxml/jackson/databind/introspect/POJOPropertyBuilder.java
+++ b/src/main/java/com/fasterxml/jackson/databind/introspect/POJOPropertyBuilder.java
@@ -1,5 +1,6 @@
package com.fasterxml.jackson.databind.introspect;
+import com.fasterxml.jackson.databind.AnnotationIntrospector;
import com.fasterxml.jackson.databind.BeanPropertyDefinition;
/**
@@ -11,6 +12,14 @@
implements Comparable<POJOPropertyBuilder>
{
/**
+ * Whether property is being composed for serialization
+ * (true) or deserialization (false)
+ */
+ protected final boolean _forSerialization;
+
+ protected final AnnotationIntrospector _annotationIntrospector;
+
+ /**
* External name of logical property; may change with
* renaming (by new instance being constructed using
* a new name)
@@ -30,21 +39,26 @@
protected Node<AnnotatedMethod> _getters;
protected Node<AnnotatedMethod> _setters;
-
- public POJOPropertyBuilder(String internalName)
+
+ public POJOPropertyBuilder(String internalName, AnnotationIntrospector annotationIntrospector,
+ boolean forSerialization)
{
_internalName = internalName;
_name = internalName;
+ _annotationIntrospector = annotationIntrospector;
+ _forSerialization = forSerialization;
}
public POJOPropertyBuilder(POJOPropertyBuilder src, String newName)
{
_internalName = src._internalName;
_name = newName;
+ _annotationIntrospector = src._annotationIntrospector;
_fields = src._fields;
_ctorParameters = src._ctorParameters;
_getters = src._getters;
_setters = src._setters;
+ _forSerialization = src._forSerialization;
}
/**
@@ -104,29 +118,6 @@
public boolean hasConstructorParameter() { return _ctorParameters != null; }
@Override
- public AnnotatedMember getAccessor()
- {
- AnnotatedMember m = getGetter();
- if (m == null) {
- m = getField();
- }
- return m;
- }
-
- @Override
- public AnnotatedMember getMutator()
- {
- AnnotatedMember m = getConstructorParameter();
- if (m == null) {
- m = getSetter();
- if (m == null) {
- m = getField();
- }
- }
- return m;
- }
-
- @Override
public boolean couldSerialize() {
return (_getters != null) || (_fields != null);
}
@@ -247,6 +238,42 @@
return _ctorParameters.value;
}
+ @Override
+ public AnnotatedMember getAccessor()
+ {
+ AnnotatedMember m = getGetter();
+ if (m == null) {
+ m = getField();
+ }
+ return m;
+ }
+
+ @Override
+ public AnnotatedMember getMutator()
+ {
+ AnnotatedMember m = getConstructorParameter();
+ if (m == null) {
+ m = getSetter();
+ if (m == null) {
+ m = getField();
+ }
+ }
+ return m;
+ }
+
+ /**
+ * Method that will try to find JSON View inclusion information
+ * for this property.
+ */
+ public Class<?>[] getViews()
+ {
+ if (_annotationIntrospector != null) {
+ AnnotatedMember m = _forSerialization ? getAccessor() : getMutator();
+ return _annotationIntrospector.findViews(m);
+ }
+ return null;
+ }
+
/*
/**********************************************************
/* Data aggregation
diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/BeanPropertyWriter.java b/src/main/java/com/fasterxml/jackson/databind/ser/BeanPropertyWriter.java
index 3ccf0ff..bca93c6 100644
--- a/src/main/java/com/fasterxml/jackson/databind/ser/BeanPropertyWriter.java
+++ b/src/main/java/com/fasterxml/jackson/databind/ser/BeanPropertyWriter.java
@@ -134,7 +134,7 @@
* Alternate set of property writers used when view-based filtering
* is available for the Bean.
*/
- protected Class<?>[] _includeInViews;
+ protected final Class<?>[] _includeInViews;
/**
* If property being serialized needs type information to be
@@ -159,25 +159,17 @@
/* Construction, configuration
/**********************************************************
*/
-
- public BeanPropertyWriter(AnnotatedMember member, Annotations contextAnnotations,
- String name, JavaType declaredType,
- JsonSerializer<Object> ser, TypeSerializer typeSer, JavaType serType,
- Method m, Field f, boolean suppressNulls, Object suppressableValue)
- {
- this(member, contextAnnotations, new SerializedString(name), declaredType,
- ser, typeSer, serType,
- m, f, suppressNulls, suppressableValue);
- }
- public BeanPropertyWriter(AnnotatedMember member, Annotations contextAnnotations,
- SerializedString name, JavaType declaredType,
+ public BeanPropertyWriter(BeanPropertyDefinition propDef,
+ AnnotatedMember member, Annotations contextAnnotations,
+ JavaType declaredType,
JsonSerializer<Object> ser, TypeSerializer typeSer, JavaType serType,
Method m, Field f, boolean suppressNulls, Object suppressableValue)
{
+
_member = member;
_contextAnnotations = contextAnnotations;
- _name = name;
+ _name = new SerializedString(propDef.getName());
_declaredType = declaredType;
_serializer = ser;
_dynamicSerializers = (ser == null) ? PropertySerializerMap.emptyMap() : null;
@@ -187,6 +179,7 @@
_field = f;
_suppressNulls = suppressNulls;
_suppressableValue = suppressableValue;
+ _includeInViews = propDef.getViews();
// this will be resolved later on, unless nulls are to be suppressed
_nullSerializer = null;
@@ -266,16 +259,6 @@
public BeanPropertyWriter unwrappingWriter(NameTransformer unwrapper) {
return new UnwrappingBeanPropertyWriter(this, unwrapper);
}
-
- /**
- * Method for defining which views to included value of this
- * property in. If left undefined, will always be included;
- * otherwise active view definition will be checked against
- * definition list and value is only included if active
- * view is one of defined views, or its sub-view (as defined
- * by class/sub-class relationship).
- */
- public void setViews(Class<?>[] views) { _includeInViews = views; }
/**
* Method called to define type to consider as "non-trivial" basetype,
diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/BeanSerializerFactory.java b/src/main/java/com/fasterxml/jackson/databind/ser/BeanSerializerFactory.java
index f7fc7a3..0efc255 100644
--- a/src/main/java/com/fasterxml/jackson/databind/ser/BeanSerializerFactory.java
+++ b/src/main/java/com/fasterxml/jackson/databind/ser/BeanSerializerFactory.java
@@ -519,7 +519,6 @@
if (properties.isEmpty()) {
return null;
}
-
// null is for value type serializer, which we don't have access to from here (ditto for bean prop)
boolean staticTyping = usesStaticTyping(config, beanDesc, null, null);
PropertyBuilder pb = constructPropertyBuilder(config, beanDesc);
@@ -534,11 +533,10 @@
if (prop != null && prop.isBackReference()) {
continue;
}
- String name = property.getName();
if (accessor instanceof AnnotatedMethod) {
- result.add(_constructWriter(prov, typeBind, pb, staticTyping, name, (AnnotatedMethod) accessor));
+ result.add(_constructWriter(property, prov, typeBind, pb, staticTyping, (AnnotatedMethod) accessor));
} else {
- result.add(_constructWriter(prov, typeBind, pb, staticTyping, name, (AnnotatedField) accessor));
+ result.add(_constructWriter(property, prov, typeBind, pb, staticTyping, (AnnotatedField) accessor));
}
}
return result;
@@ -671,11 +669,12 @@
* Secondary helper method for constructing {@link BeanPropertyWriter} for
* given member (field or method).
*/
- protected BeanPropertyWriter _constructWriter(SerializerProvider prov,
- TypeBindings typeContext,
- PropertyBuilder pb, boolean staticTyping, String name, AnnotatedMember accessor)
+ protected BeanPropertyWriter _constructWriter(BeanPropertyDefinition propDef,
+ SerializerProvider prov, TypeBindings typeContext,
+ PropertyBuilder pb, boolean staticTyping, AnnotatedMember accessor)
throws JsonMappingException
{
+ final String name = propDef.getName();
if (prov.canOverrideAccessModifiers()) {
accessor.fixAccess();
}
@@ -692,11 +691,8 @@
// and if not JAXB collection/array with annotations, maybe regular type info?
TypeSerializer typeSer = findPropertyTypeSerializer(type, prov.getConfig(), accessor, property);
- BeanPropertyWriter pbw = pb.buildWriter(name, type, annotatedSerializer,
+ BeanPropertyWriter pbw = pb.buildWriter(propDef, type, annotatedSerializer,
typeSer, contentTypeSer, accessor, staticTyping);
- // how about views? (1.4+)
- AnnotationIntrospector intr = prov.getAnnotationIntrospector();
- pbw.setViews(intr.findViews(accessor));
return pbw;
}
}
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 e7b3842..da14f26 100644
--- a/src/main/java/com/fasterxml/jackson/databind/ser/PropertyBuilder.java
+++ b/src/main/java/com/fasterxml/jackson/databind/ser/PropertyBuilder.java
@@ -55,7 +55,8 @@
* to use for contained values (only used for properties that are
* of container type)
*/
- protected BeanPropertyWriter buildWriter(String name, JavaType declaredType,
+ protected BeanPropertyWriter buildWriter(BeanPropertyDefinition propDef,
+ JavaType declaredType,
JsonSerializer<Object> ser,
TypeSerializer typeSer, TypeSerializer contentTypeSer,
AnnotatedMember am, boolean defaultUseStaticTyping)
@@ -90,7 +91,7 @@
*/
if (ct == null) {
throw new IllegalStateException("Problem trying to create BeanPropertyWriter for property '"
- +name+"' (of type "+_beanDesc.getType()+"); serialization type "+serializationType+" has no content");
+ +propDef.getName()+"' (of type "+_beanDesc.getType()+"); serialization type "+serializationType+" has no content");
}
serializationType = serializationType.withContentTypeHandler(contentTypeSer);
ct = serializationType.getContentType();
@@ -104,7 +105,7 @@
if (methodProps != null) {
switch (methodProps) {
case NON_DEFAULT:
- valueToSuppress = getDefaultValue(name, m, f);
+ valueToSuppress = getDefaultValue(propDef.getName(), m, f);
if (valueToSuppress == null) {
suppressNulls = true;
} else {
@@ -133,7 +134,8 @@
}
}
- BeanPropertyWriter bpw = new BeanPropertyWriter(am, _beanDesc.getClassAnnotations(), name, declaredType,
+ BeanPropertyWriter bpw = new BeanPropertyWriter(propDef,
+ am, _beanDesc.getClassAnnotations(), declaredType,
ser, typeSer, serializationType, m, f, suppressNulls, valueToSuppress);
// [JACKSON-132]: Unwrapping