com.fasterxml.jackson.databind.deser.impl.ObjectIdValueProperty Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jersey-all Show documentation
Show all versions of jersey-all Show documentation
jersey-all is a rebundled verison of Jersey as one OSGi bundle.
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.JsonProcessingException;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.deser.*;
import com.fasterxml.jackson.databind.introspect.AnnotatedMember;
/**
* Specialized {@link SettableBeanProperty} implementation used
* for virtual property that represents Object Id that is used
* for some POJO types (or properties).
*/
public final class ObjectIdValueProperty
extends SettableBeanProperty
{
private static final long serialVersionUID = 1L;
protected final ObjectIdReader _objectIdReader;
@Deprecated // since 2.2
public ObjectIdValueProperty(ObjectIdReader objectIdReader) {
this(objectIdReader, PropertyMetadata.STD_REQUIRED);
}
public ObjectIdValueProperty(ObjectIdReader objectIdReader,
PropertyMetadata metadata)
{
super(objectIdReader.propertyName, objectIdReader.getIdType(), metadata,
objectIdReader.getDeserializer());
_objectIdReader = objectIdReader;
}
protected ObjectIdValueProperty(ObjectIdValueProperty src, JsonDeserializer> deser)
{
super(src, deser);
_objectIdReader = src._objectIdReader;
}
@Deprecated // since 2.3
protected ObjectIdValueProperty(ObjectIdValueProperty src, PropertyName newName) {
super(src, newName);
_objectIdReader = src._objectIdReader;
}
@Deprecated // since 2.3
protected ObjectIdValueProperty(ObjectIdValueProperty src, String newName) {
this(src, new PropertyName(newName));
}
@Override
public ObjectIdValueProperty withName(PropertyName newName) {
return new ObjectIdValueProperty(this, newName);
}
@Override
public ObjectIdValueProperty withValueDeserializer(JsonDeserializer> deser) {
return new ObjectIdValueProperty(this, deser);
}
// // // BeanProperty impl
@Override
public A getAnnotation(Class acls) {
return null;
}
@Override public AnnotatedMember getMember() { return null; }
/*
/**********************************************************
/* Deserialization methods
/**********************************************************
*/
@Override
public void deserializeAndSet(JsonParser jp, DeserializationContext ctxt,
Object instance)
throws IOException, JsonProcessingException
{
deserializeSetAndReturn(jp, ctxt, instance);
}
@Override
public Object deserializeSetAndReturn(JsonParser jp,
DeserializationContext ctxt, Object instance)
throws IOException, JsonProcessingException
{
// note: no null checks (unlike usually); deserializer should fail if one found
Object id = _valueDeserializer.deserialize(jp, ctxt);
ReadableObjectId roid = ctxt.findObjectId(id, _objectIdReader.generator);
roid.bindItem(instance);
// also: may need to set a property value as well
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);
}
}