package com.fasterxml.jackson.databind.deser.impl;
import java.io.IOException;
import java.lang.annotation.Annotation;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.deser.*;
import com.fasterxml.jackson.databind.introspect.AnnotatedMember;
public final class ObjectIdValueProperty
extends SettableBeanProperty
{
private static final long serialVersionUID = 1L;
protected final ObjectIdReader _objectIdReader;
public ObjectIdValueProperty(ObjectIdReader objectIdReader,
PropertyMetadata metadata)
{
super(objectIdReader.propertyName, objectIdReader.getIdType(), metadata,
objectIdReader.getDeserializer());
_objectIdReader = objectIdReader;
}
protected ObjectIdValueProperty(ObjectIdValueProperty src, JsonDeserializer<?> deser,
NullValueProvider nva)
{
super(src, deser, nva);
_objectIdReader = src._objectIdReader;
}
protected ObjectIdValueProperty(ObjectIdValueProperty src, PropertyName newName) {
super(src, newName);
_objectIdReader = src._objectIdReader;
}
@Override
public SettableBeanProperty withName(PropertyName newName) {
return new ObjectIdValueProperty(this, newName);
}
@Override
public SettableBeanProperty withValueDeserializer(JsonDeserializer<?> deser) {
if (_valueDeserializer == deser) {
return this;
}
return new ObjectIdValueProperty(this, deser, _nullProvider);
}
@Override
public SettableBeanProperty withNullProvider(NullValueProvider nva) {
return new ObjectIdValueProperty(this, _valueDeserializer, nva);
}
@Override
public <A extends Annotation> A getAnnotation(Class<A> acls) {
return null;
}
@Override public AnnotatedMember getMember() { return null; }
@Override
public void deserializeAndSet(JsonParser p, DeserializationContext ctxt,
Object instance) throws IOException
{
deserializeSetAndReturn(p, ctxt, instance);
}
@Override
public Object deserializeSetAndReturn(JsonParser p,
DeserializationContext ctxt, Object instance) throws IOException
{
if (p.hasToken(JsonToken.VALUE_NULL)) {
return null;
}
Object id = _valueDeserializer.deserialize(p, ctxt);
ReadableObjectId roid = ctxt.findObjectId(id, _objectIdReader.generator, _objectIdReader.resolver);
roid.bindItem(instance);
SettableBeanProperty idProp = _objectIdReader.idProperty;
if (idProp != null) {
return idProp.setAndReturn(instance, id);
}
return instance;
}
@Override
public void set(Object instance, Object value) throws IOException {
setAndReturn(instance, value);
}
@Override
public Object setAndReturn(Object instance, Object value) throws IOException
{
SettableBeanProperty idProp = _objectIdReader.idProperty;
if (idProp == null) {
throw new UnsupportedOperationException(
"Should not call set() on ObjectIdProperty that has no SettableBeanProperty");
}
return idProp.setAndReturn(instance, value);
}
}