com.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 redisson-all Show documentation
Show all versions of redisson-all Show documentation
Easy Redis Java client and Real-Time Data Platform. Valkey compatible. Sync/Async/RxJava3/Reactive API. Client side caching. Over 50 Redis based Java objects and services: JCache API, Apache Tomcat, Hibernate, Spring, Set, Multimap, SortedSet, Map, List, Queue, Deque, Semaphore, Lock, AtomicLong, Map Reduce, Bloom filter, Scheduler, RPC
package com.fasterxml.jackson.databind.ser.impl;
import java.util.Iterator;
import java.util.Map.Entry;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.io.SerializedString;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper;
import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonObjectFormatVisitor;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.BeanPropertyWriter;
import com.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