下面列出了怎么用com.fasterxml.jackson.databind.util.NameTransformer的API类实例代码及写法,或者点击链接到github查看源代码。
@SuppressWarnings("unchecked")
protected ReferenceTypeSerializer(ReferenceTypeSerializer<?> base, BeanProperty property,
TypeSerializer vts, JsonSerializer<?> valueSer,
NameTransformer unwrapper,
Object suppressableValue, boolean suppressNulls)
{
super(base);
_referredType = base._referredType;
_dynamicSerializers = base._dynamicSerializers;
_property = property;
_valueTypeSerializer = vts;
_valueSerializer = (JsonSerializer<Object>) valueSer;
_unwrapper = unwrapper;
_suppressableValue = suppressableValue;
_suppressNulls = suppressNulls;
}
private final static BeanPropertyWriter[] rename(BeanPropertyWriter[] props,
NameTransformer transformer)
{
if (props == null || props.length == 0 || transformer == null || transformer == NameTransformer.NOP) {
return props;
}
final int len = props.length;
BeanPropertyWriter[] result = new BeanPropertyWriter[len];
for (int i = 0; i < len; ++i) {
BeanPropertyWriter bpw = props[i];
if (bpw != null) {
result[i] = bpw.rename(transformer);
}
}
return result;
}
@Override
protected JsonSerializer<Object> _findAndAddDynamic(PropertySerializerMap map,
Class<?> type, SerializerProvider provider) throws JsonMappingException
{
JsonSerializer<Object> serializer;
if (_nonTrivialBaseType != null) {
JavaType subtype = provider.constructSpecializedType(_nonTrivialBaseType, type);
serializer = provider.findValueSerializer(subtype, this);
} else {
serializer = provider.findValueSerializer(type, this);
}
NameTransformer t = _nameTransformer;
if (serializer.isUnwrappingSerializer()) {
t = NameTransformer.chainedTransformer(t, ((UnwrappingBeanSerializer) serializer)._nameTransformer);
}
serializer = serializer.unwrappingSerializer(t);
_dynamicSerializers = _dynamicSerializers.newWith(type, serializer);
return serializer;
}
@Override
public JsonDeserializer<Object> unwrappingDeserializer(NameTransformer transformer)
{
// bit kludgy but we don't want to accidentally change type; sub-classes
// MUST override this method to support unwrapped properties...
if (getClass() != BeanDeserializer.class) {
return this;
}
// 25-Mar-2017, tatu: Not clean at all, but for [databind#383] we do need
// to keep track of accidental recursion...
if (_currentlyTransforming == transformer) {
return this;
}
_currentlyTransforming = transformer;
try {
return new BeanDeserializer(this, transformer);
} finally { _currentlyTransforming = null; }
}
/**
* Mutant factory method for constructing a map where all entries use given
* prefix
*/
public BeanPropertyMap renameAll(NameTransformer transformer)
{
if (transformer == null || (transformer == NameTransformer.NOP)) {
return this;
}
// Try to retain insertion ordering as well
final int len = _propsInOrder.length;
ArrayList<SettableBeanProperty> newProps = new ArrayList<SettableBeanProperty>(len);
for (int i = 0; i < len; ++i) {
SettableBeanProperty prop = _propsInOrder[i];
// What to do with holes? For now, retain
if (prop == null) {
newProps.add(prop);
continue;
}
newProps.add(_rename(prop, transformer));
}
// should we try to re-index? Ordering probably changed but caller probably doesn't want changes...
// 26-Feb-2017, tatu: Probably SHOULD handle renaming wrt Aliases?
return new BeanPropertyMap(_caseInsensitive, newProps, _aliasDefs);
}
protected SettableBeanProperty _rename(SettableBeanProperty prop, NameTransformer xf)
{
if (prop == null) {
return prop;
}
String newName = xf.transform(prop.getName());
prop = prop.withSimpleName(newName);
JsonDeserializer<?> deser = prop.getValueDeserializer();
if (deser != null) {
@SuppressWarnings("unchecked")
JsonDeserializer<Object> newDeser = (JsonDeserializer<Object>)
deser.unwrappingDeserializer(xf);
if (newDeser != deser) {
prop = prop.withValueDeserializer(newDeser);
}
}
return prop;
}
public UnwrappedPropertyHandler renameAll(NameTransformer transformer)
{
ArrayList<SettableBeanProperty> newProps = new ArrayList<SettableBeanProperty>(_properties.size());
for (SettableBeanProperty prop : _properties) {
String newName = transformer.transform(prop.getName());
prop = prop.withSimpleName(newName);
JsonDeserializer<?> deser = prop.getValueDeserializer();
if (deser != null) {
@SuppressWarnings("unchecked")
JsonDeserializer<Object> newDeser = (JsonDeserializer<Object>)
deser.unwrappingDeserializer(transformer);
if (newDeser != deser) {
prop = prop.withValueDeserializer(newDeser);
}
}
newProps.add(prop);
}
return new UnwrappedPropertyHandler(newProps);
}
@Override
public JsonDeserializer<Object> unwrappingDeserializer(DeserializationContext ctxt,
NameTransformer transformer)
{
// NOTE: copied verbatim from `BeanDeserializer`
if (_currentlyTransforming == transformer) { // from [databind#383]
return this;
}
_currentlyTransforming = transformer;
try {
UnwrappedPropertyHandler uwHandler = _unwrappedPropertyHandler;
if (uwHandler != null) {
uwHandler = uwHandler.renameAll(ctxt, transformer);
}
return new SuperSonicBeanDeserializer(this, uwHandler,
_beanProperties.renameAll(ctxt, transformer), true);
} finally { _currentlyTransforming = null; }
}
@Override
public JsonDeserializer<Object> unwrappingDeserializer(DeserializationContext ctxt,
NameTransformer transformer)
{
// NOTE: copied verbatim from `BeanDeserializer`
if (_currentlyTransforming == transformer) { // from [databind#383]
return this;
}
_currentlyTransforming = transformer;
try {
UnwrappedPropertyHandler uwHandler = _unwrappedPropertyHandler;
if (uwHandler != null) {
uwHandler = uwHandler.renameAll(ctxt, transformer);
}
return new SuperSonicUnrolledDeserializer(this, uwHandler,
_beanProperties.renameAll(ctxt, transformer), true);
} finally { _currentlyTransforming = null; }
}
protected AtomicReferenceSerializer(AtomicReferenceSerializer base, BeanProperty property,
TypeSerializer vts, JsonSerializer<?> valueSer,
NameTransformer unwrapper,
Object suppressableValue, boolean suppressNulls)
{
super(base, property, vts, valueSer, unwrapper,
suppressableValue, suppressNulls);
}
@Override
protected ReferenceTypeSerializer<AtomicReference<?>> withResolved(BeanProperty prop,
TypeSerializer vts, JsonSerializer<?> valueSer,
NameTransformer unwrapper)
{
return new AtomicReferenceSerializer(this, prop, vts, valueSer, unwrapper,
_suppressableValue, _suppressNulls);
}
@Override
public JsonSerializer<T> unwrappingSerializer(NameTransformer transformer) {
JsonSerializer<Object> valueSer = _valueSerializer;
if (valueSer != null) {
valueSer = valueSer.unwrappingSerializer(transformer);
}
NameTransformer unwrapper = (_unwrapper == null) ? transformer
: NameTransformer.chainedTransformer(transformer, _unwrapper);
if ((_valueSerializer == valueSer) && (_unwrapper == unwrapper)) {
return this;
}
return withResolved(_property, _valueTypeSerializer, valueSer, unwrapper);
}
public BeanPropertyWriter rename(NameTransformer transformer) {
String newName = transformer.transform(_name.getValue());
if (newName.equals(_name.toString())) {
return this;
}
return _new(PropertyName.construct(newName));
}
@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));
}
@Override
public void assignSerializer(JsonSerializer<Object> ser)
{
if (ser != null) {
NameTransformer t = _nameTransformer;
if (ser.isUnwrappingSerializer()) {
t = NameTransformer.chainedTransformer(t, ((UnwrappingBeanSerializer) ser)._nameTransformer);
}
ser = ser.unwrappingSerializer(t);
}
super.assignSerializer(ser);
}
@Override
public JsonSerializer<Object> unwrappingSerializer(NameTransformer transformer) {
/* If this gets called, we will just need delegate to the default
* serializer, to "undo" as-array serialization
*/
return _defaultSerializer.unwrappingSerializer(transformer);
}
@Override
public JsonDeserializer<Object> unwrappingDeserializer(NameTransformer unwrapper) {
if (getClass() != ThrowableDeserializer.class) {
return this;
}
/* main thing really is to just enforce ignoring of unknown
* properties; since there may be multiple unwrapped values
* and properties for all may be interleaved...
*/
return new ThrowableDeserializer(this, unwrapper);
}
@Override
public JsonDeserializer<Object> unwrappingDeserializer(NameTransformer unwrapper)
{
/* main thing really is to just enforce ignoring of unknown
* properties; since there may be multiple unwrapped values
* and properties for all may be interleaved...
*/
return new BuilderBasedDeserializer(this, unwrapper);
}
@Override
public JsonDeserializer<Object> unwrappingDeserializer(NameTransformer unwrapper)
{
/* We can't do much about this; could either replace _delegate
* with unwrapping instance, or just replace this one. Latter seems
* more sensible.
*/
return _delegate.unwrappingDeserializer(unwrapper);
}
@Override
public JsonDeserializer<Object> unwrappingDeserializer(NameTransformer unwrapper)
{
/* We can't do much about this; could either replace _delegate
* with unwrapping instance, or just replace this one. Latter seems
* more sensible.
*/
return _delegate.unwrappingDeserializer(unwrapper);
}
public GuavaOptionalSerializer(GuavaOptionalSerializer base, BeanProperty property,
TypeSerializer vts, JsonSerializer<?> valueSer, NameTransformer unwrapper,
Object suppressableValue, boolean suppressNulls)
{
super(base, property, vts, valueSer, unwrapper,
suppressableValue, suppressNulls);
}
@Override
protected ReferenceTypeSerializer<Optional<?>> withResolved(BeanProperty prop,
TypeSerializer vts, JsonSerializer<?> valueSer,
NameTransformer unwrapper)
{
if ((_property == prop)
&& (_valueTypeSerializer == vts) && (_valueSerializer == valueSer)
&& (_unwrapper == unwrapper)) {
return this;
}
return new GuavaOptionalSerializer(this, prop, vts, valueSer, unwrapper,
_suppressableValue, _suppressNulls);
}
protected OptionSerializer(OptionSerializer base, BeanProperty property,
TypeSerializer vts, JsonSerializer<?> valueSer, NameTransformer unwrapper,
Object suppressableValue, boolean suppressNulls)
{
super(base, property, vts, valueSer, unwrapper,
suppressableValue, suppressNulls);
}
@Override
protected ReferenceTypeSerializer<Option<?>> withResolved(BeanProperty prop,
TypeSerializer vts, JsonSerializer<?> valueSer,
NameTransformer unwrapper)
{
return new OptionSerializer(this, prop, vts, valueSer, unwrapper,
_suppressableValue, _suppressNulls);
}
protected TrampolineSerializer(TrampolineSerializer base, BeanProperty property,
TypeSerializer vts, JsonSerializer<?> valueSer, NameTransformer unwrapper,
Object suppressablTrampolineue, boolean suppressNulls)
{
super(base, property, vts, valueSer, unwrapper,
suppressablTrampolineue, suppressNulls);
}
@Override
protected ReferenceTypeSerializer<Trampoline<?>> withResolved(BeanProperty prop,
TypeSerializer vts, JsonSerializer<?> valueSer,
NameTransformer unwrapper)
{
return new TrampolineSerializer(this, prop, vts, valueSer, unwrapper,
_suppressableValue, _suppressNulls);
}
protected ValueSerializer(ValueSerializer base, BeanProperty property,
TypeSerializer vts, JsonSerializer<?> valueSer, NameTransformer unwrapper,
Object suppressableValue, boolean suppressNulls)
{
super(base, property, vts, valueSer, unwrapper,
suppressableValue, suppressNulls);
}
@Override
protected ReferenceTypeSerializer<Value<?>> withResolved(BeanProperty prop,
TypeSerializer vts, JsonSerializer<?> valueSer,
NameTransformer unwrapper)
{
return new ValueSerializer(this, prop, vts, valueSer, unwrapper,
_suppressableValue, _suppressNulls);
}
protected EvalSerializer(EvalSerializer base, BeanProperty property,
TypeSerializer vts, JsonSerializer<?> valueSer, NameTransformer unwrapper,
Object suppressableValue, boolean suppressNulls)
{
super(base, property, vts, valueSer, unwrapper,
suppressableValue, suppressNulls);
}
@Override
protected ReferenceTypeSerializer<Eval<?>> withResolved(BeanProperty prop,
TypeSerializer vts, JsonSerializer<?> valueSer,
NameTransformer unwrapper)
{
return new EvalSerializer(this, prop, vts, valueSer, unwrapper,
_suppressableValue, _suppressNulls);
}