Class BeanPropertyMap
- java.lang.Object
-
- com.fasterxml.jackson.databind.deser.impl.BeanPropertyMap
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Iterable<SettableBeanProperty>
public class BeanPropertyMap extends java.lang.Object implements java.lang.Iterable<SettableBeanProperty>, java.io.Serializable
Helper class used for storing mapping from property name toSettableBeanProperty
instances.Note that this class is used instead of generic
HashMap
for bit of performance gain (and some memory savings): although default implementation is very good for generic use cases, it can be streamlined a bit for specific use case we have. Even relatively small improvements matter since this is directly on the critical path during deserialization, as it is done for each and every POJO property deserialized.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map<java.lang.String,java.util.List<PropertyName>>
_aliasDefs
Configuration of alias mappings, indexed by unmodified property name to unmodified aliases, if any; entries only included for properties that do have aliases.private java.util.Map<java.lang.String,java.lang.String>
_aliasMapping
Mapping from secondary names (aliases) to primary names.protected boolean
_caseInsensitive
private java.lang.Object[]
_hashArea
Hash area that contains key/property pairs in adjacent elements.private int
_hashMask
private java.util.Locale
_locale
We requireLocale
since case changes are locale-sensitive in certain cases (see Turkish I for example)private SettableBeanProperty[]
_propsInOrder
Array of properties in the exact order they were handed in.private int
_size
Number of entries stored in the hash area.private int
_spillCount
private static long
serialVersionUID
-
Constructor Summary
Constructors Modifier Constructor Description BeanPropertyMap(boolean caseInsensitive, java.util.Collection<SettableBeanProperty> props)
Deprecated.BeanPropertyMap(boolean caseInsensitive, java.util.Collection<SettableBeanProperty> props, java.util.Map<java.lang.String,java.util.List<PropertyName>> aliasDefs)
Deprecated.since 2.11BeanPropertyMap(boolean caseInsensitive, java.util.Collection<SettableBeanProperty> props, java.util.Map<java.lang.String,java.util.List<PropertyName>> aliasDefs, java.util.Locale locale)
protected
BeanPropertyMap(BeanPropertyMap base, boolean caseInsensitive)
private
BeanPropertyMap(BeanPropertyMap src, SettableBeanProperty newProp, int hashIndex, int orderedIndex)
private
BeanPropertyMap(BeanPropertyMap src, SettableBeanProperty newProp, java.lang.String key, int slot)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description private java.util.Map<java.lang.String,java.lang.String>
_buildAliasMapping(java.util.Map<java.lang.String,java.util.List<PropertyName>> defs, boolean caseInsensitive, java.util.Locale loc)
private SettableBeanProperty
_find2(java.lang.String key, int slot, java.lang.Object match)
private SettableBeanProperty
_find2ViaAlias(java.lang.String key, int slot, java.lang.Object match)
private int
_findFromOrdered(SettableBeanProperty prop)
private int
_findIndexInHash(java.lang.String key)
Helper method used to find exact location of a property with name given exactly, not subject to case changes, within hash area.private SettableBeanProperty
_findWithAlias(java.lang.String keyFromAlias)
private int
_hashCode(java.lang.String key)
private java.util.List<SettableBeanProperty>
_properties()
protected SettableBeanProperty
_rename(SettableBeanProperty prop, NameTransformer xf)
BeanPropertyMap
assignIndexes()
static BeanPropertyMap
construct(MapperConfig<?> config, java.util.Collection<SettableBeanProperty> props, java.util.Map<java.lang.String,java.util.List<PropertyName>> aliasMapping)
static BeanPropertyMap
construct(java.util.Collection<SettableBeanProperty> props, boolean caseInsensitive)
Deprecated.static BeanPropertyMap
construct(java.util.Collection<SettableBeanProperty> props, boolean caseInsensitive, java.util.Map<java.lang.String,java.util.List<PropertyName>> aliasMapping)
Deprecated.since 2.11SettableBeanProperty
find(int index)
SettableBeanProperty
find(java.lang.String key)
boolean
findDeserializeAndSet(com.fasterxml.jackson.core.JsonParser p, DeserializationContext ctxt, java.lang.Object bean, java.lang.String key)
Convenience method that tries to find property with given name, and if it is found, callSettableBeanProperty.deserializeAndSet(com.fasterxml.jackson.core.JsonParser, com.fasterxml.jackson.databind.DeserializationContext, java.lang.Object)
on it, and return true; or, if not found, return false.private static int
findSize(int size)
SettableBeanProperty[]
getPropertiesInInsertionOrder()
Method that will re-create initial insertion-ordering of properties contained in this map.protected java.lang.String
getPropertyName(SettableBeanProperty prop)
boolean
hasAliases()
protected void
init(java.util.Collection<SettableBeanProperty> props)
boolean
isCaseInsensitive()
java.util.Iterator<SettableBeanProperty>
iterator()
Accessor for traversing over all contained properties.void
remove(SettableBeanProperty propToRm)
Specialized method for removing specified existing entry.BeanPropertyMap
renameAll(NameTransformer transformer)
Mutant factory method for constructing a map where all entries use given prefixvoid
replace(SettableBeanProperty newProp)
Deprecated.void
replace(SettableBeanProperty origProp, SettableBeanProperty newProp)
Specialized method that can be used to replace an existing entry (note: entry MUST exist; otherwise exception is thrown) with specified replacement.int
size()
java.lang.String
toString()
BeanPropertyMap
withCaseInsensitivity(boolean state)
Mutant factory method that constructs a new instance if desired case-insensitivity state differs from the state of this instance; if states are the same, returnsthis
.BeanPropertyMap
withoutProperties(java.util.Collection<java.lang.String> toExclude)
Mutant factory method that will use this instance as the base, and construct an instance that is otherwise same except for excluding properties with specified names.BeanPropertyMap
withProperty(SettableBeanProperty newProp)
Fluent copy method that creates a new instance that is a copy of this instance except for one additional property that is passed as the argument.protected void
wrapAndThrow(java.lang.Throwable t, java.lang.Object bean, java.lang.String fieldName, DeserializationContext ctxt)
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
_caseInsensitive
protected final boolean _caseInsensitive
- Since:
- 2.5
-
_hashMask
private int _hashMask
-
_size
private int _size
Number of entries stored in the hash area.
-
_spillCount
private int _spillCount
-
_hashArea
private java.lang.Object[] _hashArea
Hash area that contains key/property pairs in adjacent elements.
-
_propsInOrder
private final SettableBeanProperty[] _propsInOrder
Array of properties in the exact order they were handed in. This is used by as-array serialization, deserialization.
-
_aliasDefs
private final java.util.Map<java.lang.String,java.util.List<PropertyName>> _aliasDefs
Configuration of alias mappings, indexed by unmodified property name to unmodified aliases, if any; entries only included for properties that do have aliases. This is is used for constructing actual reverse lookup mapping, if needed, taking into account possible case-insensitivity, as well as possibility of name prefixes.- Since:
- 2.9
-
_aliasMapping
private final java.util.Map<java.lang.String,java.lang.String> _aliasMapping
Mapping from secondary names (aliases) to primary names.- Since:
- 2.9
-
_locale
private final java.util.Locale _locale
We requireLocale
since case changes are locale-sensitive in certain cases (see Turkish I for example)- Since:
- 2.11
-
-
Constructor Detail
-
BeanPropertyMap
public BeanPropertyMap(boolean caseInsensitive, java.util.Collection<SettableBeanProperty> props, java.util.Map<java.lang.String,java.util.List<PropertyName>> aliasDefs, java.util.Locale locale)
- Since:
- 2.11
-
BeanPropertyMap
@Deprecated public BeanPropertyMap(boolean caseInsensitive, java.util.Collection<SettableBeanProperty> props, java.util.Map<java.lang.String,java.util.List<PropertyName>> aliasDefs)
Deprecated.since 2.11
-
BeanPropertyMap
private BeanPropertyMap(BeanPropertyMap src, SettableBeanProperty newProp, int hashIndex, int orderedIndex)
-
BeanPropertyMap
private BeanPropertyMap(BeanPropertyMap src, SettableBeanProperty newProp, java.lang.String key, int slot)
-
BeanPropertyMap
@Deprecated public BeanPropertyMap(boolean caseInsensitive, java.util.Collection<SettableBeanProperty> props)
Deprecated.
-
BeanPropertyMap
protected BeanPropertyMap(BeanPropertyMap base, boolean caseInsensitive)
- Since:
- 2.8
-
-
Method Detail
-
withCaseInsensitivity
public BeanPropertyMap withCaseInsensitivity(boolean state)
Mutant factory method that constructs a new instance if desired case-insensitivity state differs from the state of this instance; if states are the same, returnsthis
.- Since:
- 2.8
-
init
protected void init(java.util.Collection<SettableBeanProperty> props)
-
findSize
private static final int findSize(int size)
-
construct
public static BeanPropertyMap construct(MapperConfig<?> config, java.util.Collection<SettableBeanProperty> props, java.util.Map<java.lang.String,java.util.List<PropertyName>> aliasMapping)
- Since:
- 2.11
-
construct
@Deprecated public static BeanPropertyMap construct(java.util.Collection<SettableBeanProperty> props, boolean caseInsensitive, java.util.Map<java.lang.String,java.util.List<PropertyName>> aliasMapping)
Deprecated.since 2.11
-
construct
@Deprecated public static BeanPropertyMap construct(java.util.Collection<SettableBeanProperty> props, boolean caseInsensitive)
Deprecated.
-
withProperty
public BeanPropertyMap withProperty(SettableBeanProperty newProp)
Fluent copy method that creates a new instance that is a copy of this instance except for one additional property that is passed as the argument. Note that method does not modify this instance but constructs and returns a new one.
-
assignIndexes
public BeanPropertyMap assignIndexes()
-
renameAll
public BeanPropertyMap renameAll(NameTransformer transformer)
Mutant factory method for constructing a map where all entries use given prefix
-
withoutProperties
public BeanPropertyMap withoutProperties(java.util.Collection<java.lang.String> toExclude)
Mutant factory method that will use this instance as the base, and construct an instance that is otherwise same except for excluding properties with specified names.- Since:
- 2.8
-
replace
@Deprecated public void replace(SettableBeanProperty newProp)
Deprecated.
-
replace
public void replace(SettableBeanProperty origProp, SettableBeanProperty newProp)
Specialized method that can be used to replace an existing entry (note: entry MUST exist; otherwise exception is thrown) with specified replacement.- Since:
- 2.9.4
-
remove
public void remove(SettableBeanProperty propToRm)
Specialized method for removing specified existing entry. NOTE: entry MUST exist, otherwise an exception is thrown.
-
size
public int size()
-
isCaseInsensitive
public boolean isCaseInsensitive()
- Since:
- 2.9
-
hasAliases
public boolean hasAliases()
- Since:
- 2.9
-
iterator
public java.util.Iterator<SettableBeanProperty> iterator()
Accessor for traversing over all contained properties.- Specified by:
iterator
in interfacejava.lang.Iterable<SettableBeanProperty>
-
_properties
private java.util.List<SettableBeanProperty> _properties()
-
getPropertiesInInsertionOrder
public SettableBeanProperty[] getPropertiesInInsertionOrder()
Method that will re-create initial insertion-ordering of properties contained in this map. Note that if properties have been removed, array may contain nulls; otherwise it should be consecutive.- Since:
- 2.1
-
getPropertyName
protected final java.lang.String getPropertyName(SettableBeanProperty prop)
-
find
public SettableBeanProperty find(int index)
- Since:
- 2.3
-
find
public SettableBeanProperty find(java.lang.String key)
-
_find2
private final SettableBeanProperty _find2(java.lang.String key, int slot, java.lang.Object match)
-
_findWithAlias
private SettableBeanProperty _findWithAlias(java.lang.String keyFromAlias)
-
_find2ViaAlias
private SettableBeanProperty _find2ViaAlias(java.lang.String key, int slot, java.lang.Object match)
-
findDeserializeAndSet
public boolean findDeserializeAndSet(com.fasterxml.jackson.core.JsonParser p, DeserializationContext ctxt, java.lang.Object bean, java.lang.String key) throws java.io.IOException
Convenience method that tries to find property with given name, and if it is found, callSettableBeanProperty.deserializeAndSet(com.fasterxml.jackson.core.JsonParser, com.fasterxml.jackson.databind.DeserializationContext, java.lang.Object)
on it, and return true; or, if not found, return false. Note, too, that if deserialization is attempted, possible exceptions are wrapped if and as necessary, so caller need not handle those.- Throws:
java.io.IOException
- Since:
- 2.5
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
_rename
protected SettableBeanProperty _rename(SettableBeanProperty prop, NameTransformer xf)
-
wrapAndThrow
protected void wrapAndThrow(java.lang.Throwable t, java.lang.Object bean, java.lang.String fieldName, DeserializationContext ctxt) throws java.io.IOException
- Throws:
java.io.IOException
-
_findIndexInHash
private final int _findIndexInHash(java.lang.String key)
Helper method used to find exact location of a property with name given exactly, not subject to case changes, within hash area. Expectation is that such property SHOULD exist, although no exception is thrown.- Since:
- 2.7
-
_findFromOrdered
private final int _findFromOrdered(SettableBeanProperty prop)
-
_hashCode
private final int _hashCode(java.lang.String key)
-
_buildAliasMapping
private java.util.Map<java.lang.String,java.lang.String> _buildAliasMapping(java.util.Map<java.lang.String,java.util.List<PropertyName>> defs, boolean caseInsensitive, java.util.Locale loc)
-
-