Skip to content

Commit

Permalink
Fixed #1438
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Nov 14, 2016
1 parent 27d07a2 commit 2dbd816
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 23 deletions.
2 changes: 2 additions & 0 deletions release-notes/CREDITS
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,8 @@ Ievgen Pianov (pyanoveugen@github)
Jayson Minard (apatrida@github)
* Reported #1005: Synthetic constructors confusing Jackson data binding
(2.6.4)
* Reported #1438: `ACCEPT_CASE_INSENSITIVE_PROPERTIES` is not respected for creator properties
(2.8.5)

David Bakin (david-bakin@github)
* Reported #1013: `@JsonUnwrapped` is not treated as assuming `@JsonProperty("")`
Expand Down
2 changes: 2 additions & 0 deletions release-notes/VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ Project: jackson-databind
with more than one argument
#1432: Off by 1 bug in PropertyValueBuffer
(reported by Kevin D)
#1438: `ACCEPT_CASE_INSENSITIVE_PROPERTIES` is not respected for creator properties
(reported by Jayson M)
#1439: NPE when using with filter id, serializing `java.util.Map` types
#1441: Failure with custom Enum key deserializer, polymorphic types
(reported by Nathanial O)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.deser.SettableBeanProperty;
import com.fasterxml.jackson.databind.deser.ValueInstantiator;

Expand All @@ -21,38 +22,47 @@
*/
public final class PropertyBasedCreator
{
/**
* Number of properties: usually same as size of {@link #_propertyLookup},
* but not necessarily, when we have unnamed injectable properties.
*/
protected final int _propertyCount;

/**
* Helper object that knows how to actually construct the instance by
* invoking creator method with buffered arguments.
*/
protected final ValueInstantiator _valueInstantiator;

/**
* Map that contains property objects for either constructor or factory
* method (whichever one is null: one property for each
* parameter for that one), keyed by logical property name
*/
protected final HashMap<String, SettableBeanProperty> _propertyLookup;

/**
* Number of properties: usually same as size of {@link #_propertyLookup},
* but not necessarily, when we have unnamed injectable properties.
*/
protected final int _propertyCount;

/**
* Array that contains properties that expect value to inject, if any;
* null if no injectable values are expected.
*/
protected final SettableBeanProperty[] _allProperties;

/*
/**********************************************************
/* Construction, initialization
/**********************************************************
*/

protected PropertyBasedCreator(ValueInstantiator valueInstantiator,
SettableBeanProperty[] creatorProps)
SettableBeanProperty[] creatorProps,
boolean caseInsensitive)
{
_valueInstantiator = valueInstantiator;
_propertyLookup = new HashMap<String, SettableBeanProperty>();
if (caseInsensitive) {
_propertyLookup = new CaseInsensitiveMap();
} else {
_propertyLookup = new HashMap<String, SettableBeanProperty>();
}
final int len = creatorProps.length;
_propertyCount = len;
_allProperties = new SettableBeanProperty[len];
Expand All @@ -79,24 +89,17 @@ public static PropertyBasedCreator construct(DeserializationContext ctxt,
prop = prop.withValueDeserializer(ctxt.findContextualValueDeserializer(prop.getType(), prop));
}
creatorProps[i] = prop;
}
return new PropertyBasedCreator(valueInstantiator, creatorProps);
}
return new PropertyBasedCreator(valueInstantiator, creatorProps,
ctxt.isEnabled(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES));
}

// 05-May-2015, tatu: Does not seem to be used, commented out in 2.6
/*
public void assignDeserializer(SettableBeanProperty prop, JsonDeserializer<Object> deser) {
prop = prop.withValueDeserializer(deser);
_properties.put(prop.getName(), prop);
}
*/

/*
/**********************************************************
/* Accessors
/**********************************************************
*/

public Collection<SettableBeanProperty> properties() {
return _propertyLookup.values();
}
Expand All @@ -113,7 +116,7 @@ public SettableBeanProperty findCreatorProperty(int propertyIndex) {
}
return null;
}

/*
/**********************************************************
/* Building process
Expand Down Expand Up @@ -146,4 +149,33 @@ public Object build(DeserializationContext ctxt, PropertyValueBuffer buffer) thr
}
return bean;
}

/*
/**********************************************************
/* Helper classes
/**********************************************************
*/

/**
* Simple override of standard {@link java.util.HashMap} to support
* case-insensitive access to creator properties.
*
* @since 2.8.5
*/
static class CaseInsensitiveMap extends HashMap<String, SettableBeanProperty>
{
private static final long serialVersionUID = 1L;

@Override
public SettableBeanProperty get(Object key0) {
String key = (String) key0;
return super.get(key.toLowerCase());
}

@Override
public SettableBeanProperty put(String key, SettableBeanProperty value) {
key = key.toLowerCase();
return super.put(key, value);
}
}
}

0 comments on commit 2dbd816

Please sign in to comment.