com.fitbur.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter Maven / Gradle / Ivy
package com.fitbur.fasterxml.jackson.databind.ser.impl;
import com.fitbur.fasterxml.jackson.core.*;
import com.fitbur.fasterxml.jackson.core.io.SerializedString;
import com.fitbur.fasterxml.jackson.databind.JavaType;
import com.fitbur.fasterxml.jackson.databind.JsonMappingException;
import com.fitbur.fasterxml.jackson.databind.JsonSerializer;
import com.fitbur.fasterxml.jackson.databind.SerializerProvider;
import com.fitbur.fasterxml.jackson.databind.ser.*;
import com.fitbur.fasterxml.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
{
/**
* 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;
}
private 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: com.fitburbine transformers:
transformer = NameTransformer.chainedTransformer(transformer, _nameTransformer);
return new UnwrappingBeanPropertyWriter(this, transformer, new SerializedString(newName));
}
/*
/**********************************************************
/* Overrides
/**********************************************************
*/
@Override
public void serializeAsField(Object bean, JsonGenerator jgen, SerializerProvider prov)
throws Exception
{
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
© 2015 - 2024 Weber Informatics LLC | Privacy Policy