com.signalfx.shaded.fasterxml.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 signalfx-codahale Show documentation
Show all versions of signalfx-codahale Show documentation
Dropwizard Codahale metrics plugin for signalfx
The newest version!
package com.signalfx.shaded.fasterxml.jackson.databind.ser.impl;
import java.util.Iterator;
import java.util.Map.Entry;
import com.signalfx.shaded.fasterxml.jackson.core.JsonGenerator;
import com.signalfx.shaded.fasterxml.jackson.core.io.SerializedString;
import com.signalfx.shaded.fasterxml.jackson.databind.JavaType;
import com.signalfx.shaded.fasterxml.jackson.databind.JsonMappingException;
import com.signalfx.shaded.fasterxml.jackson.databind.JsonNode;
import com.signalfx.shaded.fasterxml.jackson.databind.JsonSerializer;
import com.signalfx.shaded.fasterxml.jackson.databind.SerializerProvider;
import com.signalfx.shaded.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper;
import com.signalfx.shaded.fasterxml.jackson.databind.jsonFormatVisitors.JsonObjectFormatVisitor;
import com.signalfx.shaded.fasterxml.jackson.databind.node.ObjectNode;
import com.signalfx.shaded.fasterxml.jackson.databind.ser.BeanPropertyWriter;
import com.signalfx.shaded.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
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
© 2015 - 2024 Weber Informatics LLC | Privacy Policy