lowentry.ue4.libs.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of lowentryue4 Show documentation
Show all versions of lowentryue4 Show documentation
A Java library for the Low Entry UE4 plugins.
package lowentry.ue4.libs.jackson.databind.ser.impl;
import java.util.Iterator;
import java.util.Map.Entry;
import lowentry.ue4.libs.jackson.core.JsonGenerator;
import lowentry.ue4.libs.jackson.core.io.SerializedString;
import lowentry.ue4.libs.jackson.databind.JavaType;
import lowentry.ue4.libs.jackson.databind.JsonMappingException;
import lowentry.ue4.libs.jackson.databind.JsonNode;
import lowentry.ue4.libs.jackson.databind.JsonSerializer;
import lowentry.ue4.libs.jackson.databind.SerializerProvider;
import lowentry.ue4.libs.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper;
import lowentry.ue4.libs.jackson.databind.jsonFormatVisitors.JsonObjectFormatVisitor;
import lowentry.ue4.libs.jackson.databind.node.ObjectNode;
import lowentry.ue4.libs.jackson.databind.ser.BeanPropertyWriter;
import lowentry.ue4.libs.jackson.databind.util.NameTransformer;
/**
* Variant of {@link BeanPropertyWriter} which will handle unwrapping
* of JSON Object (including of properties of Object within surrounding
* JSON object, and not as sub-object).
*/
public class UnwrappingBeanPropertyWriter
extends BeanPropertyWriter
implements java.io.Serializable
{
private static final long serialVersionUID = 1L;
/**
* Transformer used to add prefix and/or suffix for properties
* of unwrapped POJO.
*/
protected final NameTransformer _nameTransformer;
/*
/**********************************************************
/* Life-cycle
/**********************************************************
*/
public UnwrappingBeanPropertyWriter(BeanPropertyWriter base, NameTransformer unwrapper) {
super(base);
_nameTransformer = unwrapper;
}
protected UnwrappingBeanPropertyWriter(UnwrappingBeanPropertyWriter base, NameTransformer transformer,
SerializedString name) {
super(base, name);
_nameTransformer = transformer;
}
@Override
public UnwrappingBeanPropertyWriter rename(NameTransformer transformer)
{
String oldName = _name.getValue();
String newName = transformer.transform(oldName);
// important: combine transformers:
transformer = NameTransformer.chainedTransformer(transformer, _nameTransformer);
return _new(transformer, new SerializedString(newName));
}
/**
* Overridable factory method used by sub-classes
*
* @since 2.6.0
*/
protected UnwrappingBeanPropertyWriter _new(NameTransformer transformer, SerializedString newName)
{
return new UnwrappingBeanPropertyWriter(this, transformer, newName);
}
/*
/**********************************************************
/* Overrides, public methods
/**********************************************************
*/
@Override
public boolean isUnwrapping() {
return true;
}
@Override
public void serializeAsField(Object bean, JsonGenerator gen, SerializerProvider prov)
throws Exception
{
final Object value = get(bean);
if (value == null) {
// Hmmh. I assume we MUST pretty much suppress nulls, since we
// can't really unwrap them...
return;
}
JsonSerializer