
org.testifyproject.fasterxml.jackson.databind.ser.VirtualBeanPropertyWriter Maven / Gradle / Ivy
package org.testifyproject.testifyproject.fasterxml.jackson.databind.ser;
import java.lang.reflect.Type;
import org.testifyproject.testifyproject.fasterxml.jackson.annotation.JsonInclude;
import org.testifyproject.testifyproject.fasterxml.jackson.core.JsonGenerator;
import org.testifyproject.testifyproject.fasterxml.jackson.databind.*;
import org.testifyproject.testifyproject.fasterxml.jackson.databind.cfg.MapperConfig;
import org.testifyproject.testifyproject.fasterxml.jackson.databind.introspect.*;
import org.testifyproject.testifyproject.fasterxml.jackson.databind.jsontype.TypeSerializer;
import org.testifyproject.testifyproject.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
import org.testifyproject.testifyproject.fasterxml.jackson.databind.util.Annotations;
/**
* {@link BeanPropertyWriter} implementation used with
* {@link org.testifyproject.testifyproject.fasterxml.jackson.databind.annotation.JsonAppend}
* to add "virtual" properties in addition to regular ones.
*
* @since 2.5
*
* @see org.testifyproject.testifyproject.fasterxml.jackson.databind.ser.impl.AttributePropertyWriter
*/
public abstract class VirtualBeanPropertyWriter
extends BeanPropertyWriter
implements java.org.testifyproject.testifyproject.Serializable
{
private static final long serialVersionUID = 1L;
/**
* Constructor used by most sub-types.
*/
protected VirtualBeanPropertyWriter(BeanPropertyDefinition propDef,
Annotations contextAnnotations, JavaType org.testifyproject.testifyprojectclaredType)
{
this(propDef, contextAnnotations, org.testifyproject.testifyprojectclaredType, null, null, null,
propDef.findInclusion());
}
/**
* Constructor that may be used by sub-classes for constructing a "blue-print" instance;
* one that will only become (or create) actual usable instance when its
* {@link #withConfig} method is called.
*/
protected VirtualBeanPropertyWriter() {
super();
}
/**
* Pass-through constructor that may be used by sub-classes that
* want full control over implementation.
*/
protected VirtualBeanPropertyWriter(BeanPropertyDefinition propDef,
Annotations contextAnnotations, JavaType org.testifyproject.testifyprojectclaredType,
JsonSerializer> ser, TypeSerializer typeSer, JavaType serType,
JsonInclude.Include inclusion)
{
super(propDef, propDef.getPrimaryMember(), contextAnnotations, org.testifyproject.testifyprojectclaredType,
ser, typeSer, serType,
_suppressNulls(inclusion), _suppressableValue(inclusion));
}
protected VirtualBeanPropertyWriter(VirtualBeanPropertyWriter base) {
super(base);
}
protected VirtualBeanPropertyWriter(VirtualBeanPropertyWriter base, PropertyName name) {
super(base, name);
}
protected static boolean _suppressNulls(JsonInclude.Include inclusion) {
return (inclusion != JsonInclude.Include.ALWAYS);
}
protected static Object _suppressableValue(JsonInclude.Include inclusion) {
if ((inclusion == JsonInclude.Include.NON_EMPTY)
|| (inclusion == JsonInclude.Include.NON_EMPTY)) {
return MARKER_FOR_EMPTY;
}
return null;
}
/*
/**********************************************************
/* Standard accessor overrides
/**********************************************************
*/
@Override
public boolean isVirtual() { return true; }
@Override
public Class> getPropertyType() {
return _declaredType.getRawClass();
}
@Override
public Type getGenericPropertyType() {
return getPropertyType();
}
/*
/**********************************************************
/* Abstract methods for sub-classes to org.testifyproject.testifyprojectfine
/**********************************************************
*/
/**
* Method called to figure out the value to serialize. For simple sub-types
* (such as {@link org.testifyproject.testifyproject.fasterxml.jackson.databind.ser.impl.AttributePropertyWriter})
* this may be one of few methods to org.testifyproject.testifyprojectfine, although more advanced implementations
* may choose to not even use this method (by overriding {@link #serializeAsField})
* and org.testifyproject.testifyprojectfine a bogus implementation.
*/
protected abstract Object value(Object bean, JsonGenerator jgen, SerializerProvider prov) throws Exception;
/**
* Contextualization method called on a newly constructed virtual bean property.
* Usually a new intance needs to be created due to finality of some of configuration
* members; otherwise while recommended, creating a new instance is not strictly-speaking
* mandatory because calls are made in thread-safe manner, as part of initialization
* before use.
*
* @param config Currenct configuration; guaranteed to be {@link SerializationConfig}
* (just not typed since caller does not have org.testifyproject.testifyprojectpendency to serialization-specific types)
* @param org.testifyproject.testifyprojectclaringClass Class that contains this property writer
* @param propDef Nominal property org.testifyproject.testifyprojectfinition to use
* @param type Declared type for the property
*/
public abstract VirtualBeanPropertyWriter withConfig(MapperConfig> config,
AnnotatedClass org.testifyproject.testifyprojectclaringClass, BeanPropertyDefinition propDef, JavaType type);
/*
/**********************************************************
/* PropertyWriter serialization method overrides
/**********************************************************
*/
@Override
public void serializeAsField(Object bean, JsonGenerator gen, SerializerProvider prov) throws Exception
{
// NOTE: mostly copied from base class, but off-lined get() access
final Object value = value(bean, gen, prov);
if (value == null) {
if (_nullSerializer != null) {
gen.writeFieldName(_name);
_nullSerializer.serialize(null, gen, prov);
}
return;
}
JsonSerializer
© 2015 - 2025 Weber Informatics LLC | Privacy Policy