Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.fasterxml.jackson.annotation;

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

Parameters:
<T> Type of Object Identifiers produced.
 
 public abstract class ObjectIdGenerator<T>
 {
     /*
     /**********************************************************
     /* Accessors
     /**********************************************************
      */
 
     public abstract Class<?> getScope();

    
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(java.lang.Object)).

Returns:
True if this instance can be used as-is; false if not
 
     public abstract boolean canUseFor(ObjectIdGenerator<?> gen);
     
     /*
     /**********************************************************
     /* Factory methods
     /**********************************************************
      */
    
    
Factory method to create a blueprint instance for specified scope. Generators that do not use scope may return 'this'.
 
     public abstract ObjectIdGenerator<T> forScope(Class<?> scope);
    
    
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 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.
 
     public abstract ObjectIdGenerator<T> newForSerialization(Object context);

    
Method for constructing key to use for ObjectId-to-POJO maps.
 
     public abstract IdKey key(Object key);
     
     /*
     /**********************************************************
     /* Methods for serialization
     /**********************************************************
      */
    
    
Method used for generating a new Object Identifier to serialize for given POJO.

Parameters:
forPojo POJO for which identifier is needed
Returns:
Object Identifier to use.
 
     public abstract T generateId(Object forPojo);
 
     /*
     /**********************************************************
     /* Helper classes
     /**********************************************************
      */

    
Simple key class that can be used as a key for ObjectId-to-POJO mappings, when multiple ObjectId types and scopes are used.
 
     public final static class IdKey
     {
        
Type of ObjectIdGenerator used for generating Object Id
 
         private final Class<?> type;

        
Scope of the Object Id (may be null, to denote global)
        private final Class<?> scope;

        
Object for which Object Id was generated: can NOT be null.
        private final Object key;

        
Hash code
        private final int hashCode;
        
        public IdKey(Class<?> typeClass<?> scopeObject key) {
            this. = type;
            this. = scope;
            this. = key;
            
            int h = key.hashCode() + type.getName().hashCode();
            if (scope != null) {
                h ^= scope.getName().hashCode();
            }
             = h;
        }
        @Override
        public int hashCode() { return ; }
        @Override
        public boolean equals(Object o)
        {
            if (o == thisreturn true;
            if (o == nullreturn false;
            if (o.getClass() != getClass()) return false;
            IdKey other = (IdKeyo;
            return (other.key.equals()) && (other.type == ) && (other.scope == );
        }
    }
New to GrepCode? Check out our FAQ X