Top Description Inners Constructors Methods
com.fasterxml.jackson.annotation

public abstract Class ObjectIdGenerator<T>

extends Object
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Known Direct Subclasses
com.fasterxml.jackson.annotation.ObjectIdGenerators.Base, com.fasterxml.jackson.annotation.ObjectIdGenerators.None
Annotations
@SuppressWarnings:serial
Type Parameters
<T>
Type of Object Identifiers produced.

Definition of API used for constructing Object Identifiers (as annotated using JsonIdentityInfo). Also defines factory methods used for creating instances for serialization, deserialization.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
ObjectIdGenerator.IdKey

Simple key class that can be used as a key for ObjectId-to-POJO mappings, when multiple ObjectId types and scopes are used.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public abstract boolean

Returns:

True if this instance can be used as-is; false if not
canUseFor
(ObjectIdGenerator<?> gen)

Method called to check whether this generator instance can be used for Object Ids of specific generator type and scope; determination is based by passing a configured "blueprint" (prototype) instance; from which the actual instances are created (using newForSerialization).

public abstract ObjectIdGenerator<T>
forScope(Class<?> scope)

Factory method to create a blueprint instance for specified scope.

public abstract T

Returns:

Object Identifier to use.
generateId
(Object
POJO for which identifier is needed
forPojo
)

Method used for generating a new Object Identifier to serialize for given POJO.

public abstract Class<?>
public boolean
isValidReferencePropertyName(String
Name of property to check
name
,
Object
Parser that points to property name, in case generator needs further verification (note: untyped, because JsonParser is defined in `jackson-core`, and this package does not depend on it).
parser
)

Accessor that may be called (after verifying (via maySerializeAsObject()) whether given name

public abstract ObjectIdGenerator.IdKey
key(Object key)

Method for constructing key to use for ObjectId-to-POJO maps.

public boolean
maySerializeAsObject()

Accessor that needs to be overridden to return true if the Object Id may be serialized as JSON Object; used by, for example, JSOG handling.

public abstract ObjectIdGenerator<T>
newForSerialization(Object
Serialization context object used (of type com.fasterxml.jackson.databind.SerializerProvider); may be needed by more complex generators to access contextual information such as configuration.
context
)

Factory method called to create a new instance to use for serialization: needed since generators may have state (next id to produce).

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

ObjectIdGeneratorback to summary
public ObjectIdGenerator()

Method Detail

canUseForback to summary
public abstract boolean canUseFor(ObjectIdGenerator<?> gen)

Method called to check whether this generator instance can be used for Object Ids of specific generator type and scope; determination is based by passing a configured "blueprint" (prototype) instance; from which the actual instances are created (using newForSerialization).

Returns:boolean

True if this instance can be used as-is; false if not

forScopeback to summary
public abstract ObjectIdGenerator<T> forScope(Class<?> scope)

Factory method to create a blueprint instance for specified scope. Generators that do not use scope may return 'this'.

generateIdback to summary
public abstract T generateId(Object forPojo)

Method used for generating a new Object Identifier to serialize for given POJO.

Parameters
forPojo:Object

POJO for which identifier is needed

Returns:T

Object Identifier to use.

getScopeback to summary
public abstract Class<?> getScope()
isValidReferencePropertyNameback to summary
public boolean isValidReferencePropertyName(String name, Object parser)

Accessor that may be called (after verifying (via maySerializeAsObject()) whether given name

Parameters
name:String

Name of property to check

parser:Object

Parser that points to property name, in case generator needs further verification (note: untyped, because JsonParser is defined in `jackson-core`, and this package does not depend on it).

Since
2.5
keyback to summary
public abstract ObjectIdGenerator.IdKey key(Object key)

Method for constructing key to use for ObjectId-to-POJO maps.

maySerializeAsObjectback to summary
public boolean maySerializeAsObject()

Accessor that needs to be overridden to return true if the Object Id may be serialized as JSON Object; used by, for example, JSOG handling. The reason accessor is needed is that handling such Object Ids is more complex and may incur additional buffering or performance overhead, avoiding of which makes sense for common case of scalar object ids (or native object ids some formats support).

Default implementation returns false, so needs to be overridden by Object-producing generators.

Since
2.5
newForSerializationback to summary
public abstract ObjectIdGenerator<T> newForSerialization(Object context)

Factory method called to create a new instance to use for serialization: needed since generators may have state (next id to produce).

Note that actual type of 'context' is com.fasterxml.jackson.databind.SerializerProvider, but can not be declared here as type itself (as well as call to this object) comes from databind package.

Parameters
context:Object

Serialization context object used (of type com.fasterxml.jackson.databind.SerializerProvider); may be needed by more complex generators to access contextual information such as configuration.

com.fasterxml.jackson.annotation back to summary

public final Class ObjectIdGenerator.IdKey

extends Object
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable

Simple key class that can be used as a key for ObjectId-to-POJO mappings, when multiple ObjectId types and scopes are used.

Field Summary

Modifier and TypeField and Description
private final int
public final Object
key

Object for which Object Id was generated: can NOT be null.

public final Class<?>
scope

Scope of the Object Id (may be null, to denote global)

private static final long
public final Class<?>
type

Type of ObjectIdGenerator used for generating Object Id

Constructor Summary

AccessConstructor and Description
public
IdKey(Class<?> type, Class<?> scope, Object key)

Method Summary

Modifier and TypeMethod and Description
public boolean
equals(Object
the reference object with which to compare.
o
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

hashCodeback to summary
private final int hashCode
keyback to summary
public final Object key

Object for which Object Id was generated: can NOT be null.

scopeback to summary
public final Class<?> scope

Scope of the Object Id (may be null, to denote global)

serialVersionUIDback to summary
private static final long serialVersionUID
typeback to summary
public final Class<?> type

Type of ObjectIdGenerator used for generating Object Id

Constructor Detail

IdKeyback to summary
public IdKey(Class<?> type, Class<?> scope, Object key)

Method Detail

equalsback to summary
public boolean equals(Object o)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
o:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override