com.fasterxml.jackson.annotation

Class ObjectIdGenerators.StringIdGenerator

  • All Implemented Interfaces:
    Serializable
    Enclosing class:
    ObjectIdGenerators


    public static final class ObjectIdGenerators.StringIdGenerator
    extends ObjectIdGenerator<T>
    Implementation that will accept arbitrary (but unique) String Ids on deserialization, and (by default) use random UUID generation similar to ObjectIdGenerators.UUIDGenerator for generation ids.

    This generator is most useful for cases where another system creates String Ids (of arbitrary structure, if any), and Jackson only needs to keep track of id-to-Object mapping. Generation also works, although if UUIDs are always used, ObjectIdGenerators.UUIDGenerator is a better match as it will also validate ids being used.

    Since:
    2.7
    See Also:
    Serialized Form
    • Constructor Detail

      • StringIdGenerator

        public StringIdGenerator()
    • Method Detail

      • newForSerialization

        public ObjectIdGenerator<String> newForSerialization(Object context)
        Description copied from class: ObjectIdGenerator
        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.

        Specified by:
        newForSerialization in class ObjectIdGenerator<String>
        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.
      • generateId

        public String generateId(Object forPojo)
        Description copied from class: ObjectIdGenerator
        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.
      • canUseFor

        public boolean canUseFor(ObjectIdGenerator<?> gen)
        Description copied from class: ObjectIdGenerator
        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 ObjectIdGenerator.newForSerialization(java.lang.Object)).
        Returns:
        True if this instance can be used as-is; false if not

Copyright © 2008–2024 FasterXML. All rights reserved.