Skip to content

Commit

Permalink
Fix #899
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Aug 14, 2015
1 parent eda66cc commit 2ea6e40
Show file tree
Hide file tree
Showing 12 changed files with 124 additions and 57 deletions.
4 changes: 4 additions & 0 deletions release-notes/VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ Project: jackson-databind
=== Releases ===
------------------------------------------------------------------------

2.6.2 (not yet released)

#899: Problem serializing `ObjectReader` (and possibly `ObjectMapper`)

2.6.1 (09-Aug-2015)

#873: Add missing OSGi import
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,12 @@
*/
@JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
public class BeanPropertyWriter extends PropertyWriter
implements BeanProperty
implements BeanProperty,
java.io.Serializable // since 2.6.2
{
// as of 2.6.2
private static final long serialVersionUID = 4603296144163950020L;

/**
* Marker object used to indicate "do not serialize if empty"
*/
Expand All @@ -50,54 +54,7 @@ public class BeanPropertyWriter extends PropertyWriter
* @since 2.6
*/
protected final static JsonFormat.Value NO_FORMAT = new JsonFormat.Value();

/*
/**********************************************************
/* Settings for accessing property value to serialize
/**********************************************************
*/

/**
* Member (field, method) that represents property and allows access
* to associated annotations.
*/
protected final AnnotatedMember _member;

/**
* Annotations from context (most often, class that declares property,
* or in case of sub-class serializer, from that sub-class)
*/
protected final Annotations _contextAnnotations;

/**
* Type property is declared to have, either in class definition
* or associated annotations.
*/
protected final JavaType _declaredType;

/**
* Accessor method used to get property value, for
* method-accessible properties.
* Null if and only if {@link #_field} is null.
*/
protected final Method _accessorMethod;

/**
* Field that contains the property value for field-accessible
* properties.
* Null if and only if {@link #_accessorMethod} is null.
*/
protected final Field _field;

/*
/**********************************************************
/* Opaque internal data that bean serializer factory and
/* bean serializers can add.
/**********************************************************
*/

protected HashMap<Object,Object> _internalSettings;

/*
/**********************************************************
/* Basic property metadata: name, type, other
Expand All @@ -122,6 +79,12 @@ public class BeanPropertyWriter extends PropertyWriter
*/
protected final PropertyName _wrapperName;

/**
* Type property is declared to have, either in class definition
* or associated annotations.
*/
protected final JavaType _declaredType;

/**
* Type to use for locating serializer; normally same as return
* type of the accessor method, but may be overridden by annotations.
Expand All @@ -137,6 +100,15 @@ public class BeanPropertyWriter extends PropertyWriter
*/
protected JavaType _nonTrivialBaseType;

/**
* Annotations from context (most often, class that declares property,
* or in case of sub-class serializer, from that sub-class)
*<p>
* NOTE: transient just to support JDK serializability; Annotations
* do not serialize. At all.
*/
protected final transient Annotations _contextAnnotations;

/**
* Additional information about property
*
Expand All @@ -151,6 +123,36 @@ public class BeanPropertyWriter extends PropertyWriter
*/
protected transient JsonFormat.Value _format;

/*
/**********************************************************
/* Settings for accessing property value to serialize
/**********************************************************
*/

/**
* Member (field, method) that represents property and allows access
* to associated annotations.
*/
protected final AnnotatedMember _member;

/**
* Accessor method used to get property value, for
* method-accessible properties.
* Null if and only if {@link #_field} is null.
*<p>
* `transient` (and non-final) only to support JDK serializability.
*/
protected transient Method _accessorMethod;

/**
* Field that contains the property value for field-accessible
* properties.
* Null if and only if {@link #_accessorMethod} is null.
*<p>
* `transient` (and non-final) only to support JDK serializability.
*/
protected transient Field _field;

/*
/**********************************************************
/* Serializers needed
Expand Down Expand Up @@ -211,6 +213,15 @@ public class BeanPropertyWriter extends PropertyWriter
*/
protected final Class<?>[] _includeInViews;

/*
/**********************************************************
/* Opaque internal data that bean serializer factory and
/* bean serializers can add.
/**********************************************************
*/

protected transient HashMap<Object,Object> _internalSettings;

/*
/**********************************************************
/* Construction, configuration
Expand Down Expand Up @@ -301,16 +312,18 @@ protected BeanPropertyWriter(BeanPropertyWriter base, PropertyName name)
/* 02-Dec-2014, tatu: This is a big mess, alas, what with dependency
* to MapperConfig to encode, and Afterburner having heartburn
* for SerializableString (vs SerializedString).
* Hope it can be resolved/reworker in 2.6 timeframe, if not for 2.5
* Hope it can be resolved/reworked in 2.6 timeframe, if not for 2.5
*/
_name = new SerializedString(name.getSimpleName());
_wrapperName = base._wrapperName;

_member = base._member;
_contextAnnotations = base._contextAnnotations;
_declaredType = base._declaredType;

_member = base._member;
_accessorMethod = base._accessorMethod;
_field = base._field;

_serializer = base._serializer;
_nullSerializer = base._nullSerializer;
// one more thing: copy internal settings, if any (since 1.7)
Expand Down Expand Up @@ -421,6 +434,30 @@ public void setNonTrivialBaseType(JavaType t) {
_nonTrivialBaseType = t;
}

/*
/**********************************************************
/* JDK Serializability
/**********************************************************
*/

/* Ideally would not require mutable state, and instead would re-create with
* final settings. However, as things are, with sub-types and all, simplest
* to just change Field/Method value directly.
*/
Object readResolve() {
if (_member instanceof AnnotatedField) {
_accessorMethod = null;
_field = (Field) _member.getMember();
} else if (_member instanceof AnnotatedMethod) {
_accessorMethod = (Method) _member.getMember();
_field = null;
}
if (_serializer == null) {
_dynamicSerializers = PropertySerializerMap.emptyForProperties();
}
return this;
}

/*
/**********************************************************
/* BeanProperty impl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
public class BeanSerializer
extends BeanSerializerBase
{
private static final long serialVersionUID = -4536893235025590367L;
private static final long serialVersionUID = -3618164443537292758L;

/*
/**********************************************************
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@
*/
public abstract class VirtualBeanPropertyWriter
extends BeanPropertyWriter
implements java.io.Serializable
{
private static final long serialVersionUID = 1L;

/**
* Constructor used by most sub-types.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
public class AttributePropertyWriter
extends VirtualBeanPropertyWriter
{
private static final long serialVersionUID = 1;

protected final String _attrName;

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ public static BeanPropertyWriter constructViewBased(BeanPropertyWriter base, Cla

private final static class SingleView
extends BeanPropertyWriter
implements java.io.Serializable
{
private static final long serialVersionUID = 1L;

protected final BeanPropertyWriter _delegate;

protected final Class<?> _view;
Expand Down Expand Up @@ -82,7 +85,10 @@ public void serializeAsElement(Object bean, JsonGenerator jgen, SerializerProvid

private final static class MultiView
extends BeanPropertyWriter
implements java.io.Serializable
{
private static final long serialVersionUID = 1L;

protected final BeanPropertyWriter _delegate;

protected final Class<?>[] _views;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@
*/
public class UnwrappingBeanPropertyWriter
extends BeanPropertyWriter
implements java.io.Serializable
{
private static final long serialVersionUID = 1L;

/**
* Transformer used to add prefix and/or suffix for properties
* of unwrapped POJO.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

public class UnwrappingBeanSerializer
extends BeanSerializerBase
implements java.io.Serializable
{
private static final long serialVersionUID = 1L;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
* enumerations.
*/
public final class EnumValues
implements java.io.Serializable
{
private static final long serialVersionUID = 1;

private final Class<Enum<?>> _enumClass;

private final Enum<?>[] _values;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@ public abstract class NameTransformer
* Singleton "no-operation" transformer which simply returns given
* name as is. Used commonly as placeholder or marker.
*/
public final static NameTransformer NOP = new NameTransformer() {
public final static NameTransformer NOP = new NopTransformer();

protected final static class NopTransformer
extends NameTransformer
implements java.io.Serializable
{
private static final long serialVersionUID = 1L;

@Override
public String transform(String name) {
return name;
Expand All @@ -21,7 +28,7 @@ public String reverse(String transformed) {
// identity transformation is always reversible:
return transformed;
}
};
}

protected NameTransformer() { }

Expand Down Expand Up @@ -107,7 +114,10 @@ public static NameTransformer chainedTransformer(NameTransformer t1, NameTransfo
public abstract String reverse(String transformed);

public static class Chained extends NameTransformer
implements java.io.Serializable
{
private static final long serialVersionUID = 1L;

protected final NameTransformer _t1, _t2;

public Chained(NameTransformer t1, NameTransformer t2) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,7 @@ public void testEnumHandlers() throws IOException
/* 14-Aug-2015, tatu: Looks like pre-loading JsonSerializer is problematic
* at this point; comment out for now. Try to fix later on.
*/

// bytes = jdkSerialize(mapper.writerFor(EnumPOJO.class));
bytes = jdkSerialize(mapper.writer());
bytes = jdkSerialize(mapper.writerFor(EnumPOJO.class));
ObjectWriter w = jdkDeserialize(bytes);
assertNotNull(w);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonGenerator;

import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.annotation.JsonAppend;
import com.fasterxml.jackson.databind.cfg.MapperConfig;
Expand Down Expand Up @@ -45,6 +44,7 @@ static class OptionalsBean
public int value = 28;
}

@SuppressWarnings("serial")
static class CustomVProperty
extends VirtualBeanPropertyWriter
{
Expand Down

0 comments on commit 2ea6e40

Please sign in to comment.