下面列出了怎么用com.fasterxml.jackson.annotation.ObjectIdGenerator.IdKey的API类实例代码及写法,或者点击链接到github查看源代码。
@Override
public void bindItem(IdKey id, Object ob)
{
if (_items == null) {
_items = new HashMap<IdKey,Object>();
} else if (_items.containsKey(id)) {
throw new IllegalStateException("Already had POJO for id (" + id.key.getClass().getName() + ") [" + id
+ "]");
}
_items.put(id, ob);
}
/**
* {@inheritDoc}
*
* <p>addObjectId</p>
*/
@Override
public void addObjectId(IdKey id, Object instance) {
if (null == idToObject) {
idToObject = new HashMap<IdKey, Object>();
}
idToObject.put(id, instance);
}
/**
* {@inheritDoc}
*
* <p>getObjectWithId</p>
*/
@Override
public Object getObjectWithId(IdKey id) {
if (null != idToObject) {
return idToObject.get(id);
}
return null;
}
@Override
public void checkUnresolvedObjectId() throws UnresolvedForwardReference
{
if (_objectIds == null) {
return;
}
// 29-Dec-2014, tatu: As per [databind#299], may also just let unresolved refs be...
if (!isEnabled(DeserializationFeature.FAIL_ON_UNRESOLVED_OBJECT_IDS)) {
return;
}
UnresolvedForwardReference exception = null;
for (Entry<IdKey,ReadableObjectId> entry : _objectIds.entrySet()) {
ReadableObjectId roid = entry.getValue();
if (!roid.hasReferringProperties()) {
continue;
}
// as per [databind#675], allow resolution at this point
if (tryToResolveUnresolvedObjectId(roid)) {
continue;
}
if (exception == null) {
exception = new UnresolvedForwardReference(getParser(), "Unresolved forward references for: ");
}
Object key = roid.getKey().key;
for (Iterator<Referring> iterator = roid.referringProperties(); iterator.hasNext(); ) {
Referring referring = iterator.next();
exception.addUnresolvedId(key, referring.getBeanType(), referring.getLocation());
}
}
if (exception != null) {
throw exception;
}
}
/**
* <p>addObjectId</p>
*
* @param id a {@link com.fasterxml.jackson.annotation.ObjectIdGenerator.IdKey} object.
* @param instance a {@link java.lang.Object} object.
*/
public void addObjectId( IdKey id, Object instance ) {
if ( null == idToObject ) {
idToObject = new HashMap<IdKey, Object>();
}
idToObject.put( id, instance );
}
@Override
public Object resolveId(IdKey id) {
return (_items == null) ? null : _items.get(id);
}
/** {@inheritDoc} */
@Override
public IdKey newIdKey(Object id) {
return new IdKey(type, scope, id);
}
/** {@inheritDoc} */
@Override
public IdKey newIdKey(Object id) {
return new IdKey(type, scope, id);
}
/** {@inheritDoc} */
@Override
public IdKey newIdKey( Object id ) {
return new IdKey( type, scope, id );
}
/** {@inheritDoc} */
@Override
public IdKey newIdKey( Object id ) {
return new IdKey( type, scope, id );
}
@Override
public Object resolveId(IdKey id) {
return ImmutableByid.builder()
.id(id.key.toString())
.build();
}
/**
* <p>getObjectWithId</p>
*
* @param id a {@link com.fasterxml.jackson.annotation.ObjectIdGenerator.IdKey} object.
*
* @return a {@link java.lang.Object} object.
*/
public Object getObjectWithId( IdKey id ) {
if ( null != idToObject ) {
return idToObject.get( id );
}
return null;
}
/**
* Method called when a POJO is deserialized and has an Object Identifier.
* Method exists so that implementation can keep track of existing object in
* JSON stream that could be useful for further resolution.
*
* @param id The Object Identifer
* @param pojo The POJO associated to that Identifier
*/
void bindItem(IdKey id, Object pojo);
/**
* Method called when deserialization encounters the given Object Identifier
* and requires the POJO associated with it.
*
* @param id The Object Identifier
* @return The POJO, or null if unable to resolve.
*/
Object resolveId(IdKey id);
/**
* <p>newIdKey</p>
*
* @param id Identifier
* @return a new {@link com.fasterxml.jackson.annotation.ObjectIdGenerator.IdKey}
*/
IdKey newIdKey(Object id);
/**
* Overridable factory method to create a new instance of ReadableObjectId or its
* subclass. It is meant to be overridden when custom ReadableObjectId is
* needed for {@link #tryToResolveUnresolvedObjectId}.
* Default implementation simply constructs default {@link ReadableObjectId} with
* given <code>key</code>.
*
* @param key The key to associate with the new ReadableObjectId
* @return New ReadableObjectId instance
*
* @since 2.7
*/
protected ReadableObjectId createReadableObjectId(IdKey key) {
return new ReadableObjectId(key);
}
/**
* <p>newIdKey</p>
*
* @param id Identifier
* @return a new {@link IdKey}
*/
IdKey newIdKey( Object id );