
com.fasterxml.jackson.annotation.ObjectIdGenerators Maven / Gradle / Ivy
/*
* Copyright © 2019 Dominokit
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.fasterxml.jackson.annotation;
import java.util.UUID;
/**
* Container class for standard {@link ObjectIdGenerator} implementations:
*
*
* - {@link IntSequenceGenerator}
*
- {@link PropertyGenerator}
*
- {@link StringIdGenerator} (since 2.7)
*
- {@link UUIDGenerator}
*
*
* NOTE: {@link PropertyGenerator} applicability is limited in one case: it can only be used on
* polymorphic base types (ones indicated using {@link JsonTypeInfo} or default typing) via class
* annotations: property annotation will fail due to lack of access to property, needed to determine
* type of Object Id for deserialization. This limitation may be lifted in future versions but it is
* the limitation at least up to and including Jackson 2.9.
*/
public class ObjectIdGenerators {
/** Shared base class for concrete implementations. */
@SuppressWarnings("serial")
private abstract static class Base extends ObjectIdGenerator {
protected final Class> _scope;
protected Base(Class> scope) {
_scope = scope;
}
@Override
public final Class> getScope() {
return _scope;
}
@Override
public boolean canUseFor(ObjectIdGenerator> gen) {
return (gen.getClass() == getClass()) && (gen.getScope() == _scope);
}
@Override
public abstract T generateId(Object forPojo);
}
/*
/**********************************************************
/* Implementation classes
/**********************************************************
*/
/**
* Abstract marker class used to allow explicitly specifying that no generator is used; which also
* implies that no Object Id is to be included or used.
*/
@SuppressWarnings("serial")
public abstract static class None extends ObjectIdGenerator