Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
com.fasterxml.jackson.databind.deser.impl.BeanAsArrayBuilderDeserializer Maven / Gradle / Ivy
Go to download
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.deser.impl;
import java.io.IOException;
import java.util.Set;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.deser.*;
import com.fasterxml.jackson.databind.introspect.AnnotatedMethod;
import com.fasterxml.jackson.databind.util.ClassUtil;
import com.fasterxml.jackson.databind.util.NameTransformer;
public class BeanAsArrayBuilderDeserializer
extends BeanDeserializerBase
{
private static final long serialVersionUID = 1L ;
final protected BeanDeserializerBase _delegate;
final protected SettableBeanProperty[] _orderedProperties;
final protected AnnotatedMethod _buildMethod;
protected final JavaType _targetType;
public BeanAsArrayBuilderDeserializer (BeanDeserializerBase delegate,
JavaType targetType,
SettableBeanProperty[] ordered,
AnnotatedMethod buildMethod)
{
super (delegate);
_delegate = delegate;
_targetType = targetType;
_orderedProperties = ordered;
_buildMethod = buildMethod;
}
@Override
public JsonDeserializer unwrappingDeserializer (NameTransformer unwrapper)
{
return _delegate.unwrappingDeserializer(unwrapper);
}
@Override
public BeanDeserializerBase withObjectIdReader (ObjectIdReader oir) {
return new BeanAsArrayBuilderDeserializer(_delegate.withObjectIdReader(oir),
_targetType, _orderedProperties, _buildMethod);
}
@Override
public BeanDeserializerBase withByNameInclusion (Set ignorableProps,
Set includableProps) {
return new BeanAsArrayBuilderDeserializer(_delegate.withByNameInclusion(ignorableProps, includableProps),
_targetType, _orderedProperties, _buildMethod);
}
@Override
public BeanDeserializerBase withIgnoreAllUnknown (boolean ignoreUnknown) {
return new BeanAsArrayBuilderDeserializer(_delegate.withIgnoreAllUnknown(ignoreUnknown),
_targetType, _orderedProperties, _buildMethod);
}
@Override
public BeanDeserializerBase withBeanProperties (BeanPropertyMap props) {
return new BeanAsArrayBuilderDeserializer(_delegate.withBeanProperties(props),
_targetType, _orderedProperties, _buildMethod);
}
@Override
protected BeanDeserializerBase asArrayDeserializer () {
return this ;
}
@Override
public Boolean supportsUpdate (DeserializationConfig config) {
return Boolean.FALSE;
}
protected final Object finishBuild (DeserializationContext ctxt, Object builder)
throws IOException
{
try {
return _buildMethod.getMember().invoke(builder, (Object[]) null );
} catch (Exception e) {
return wrapInstantiationProblem(e, ctxt);
}
}
@Override
public Object deserialize (JsonParser p, DeserializationContext ctxt)
throws IOException
{
if (!p.isExpectedStartArrayToken()) {
return finishBuild(ctxt, _deserializeFromNonArray(p, ctxt));
}
if (!_vanillaProcessing) {
return finishBuild(ctxt, _deserializeNonVanilla(p, ctxt));
}
Object builder = _valueInstantiator.createUsingDefault(ctxt);
final SettableBeanProperty[] props = _orderedProperties;
int i = 0 ;
final int propCount = props.length;
while (true ) {
if (p.nextToken() == JsonToken.END_ARRAY) {
return finishBuild(ctxt, builder);
}
if (i == propCount) {
break ;
}
SettableBeanProperty prop = props[i];
if (prop != null ) {
try {
builder = prop.deserializeSetAndReturn(p, ctxt, builder);
} catch (Exception e) {
wrapAndThrow(e, builder, prop.getName(), ctxt);
}
} else {
p.skipChildren();
}
++i;
}
if (!_ignoreAllUnknown && ctxt.isEnabled(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)) {
ctxt.reportInputMismatch(handledType(),
"Unexpected JSON values; expected at most %d properties (in JSON Array)" ,
propCount);
}
while (p.nextToken() != JsonToken.END_ARRAY) {
p.skipChildren();
}
return finishBuild(ctxt, builder);
}
@Override
public Object deserialize (JsonParser p, DeserializationContext ctxt, Object value)
throws IOException
{
return _delegate.deserialize(p, ctxt, value);
}
@Override
public Object deserializeFromObject (JsonParser p, DeserializationContext ctxt) throws IOException
{
return _deserializeFromNonArray(p, ctxt);
}
protected Object _deserializeNonVanilla (JsonParser p, DeserializationContext ctxt)
throws IOException
{
if (_nonStandardCreation) {
return deserializeFromObjectUsingNonDefault(p, ctxt);
}
Object builder = _valueInstantiator.createUsingDefault(ctxt);
if (_injectables != null ) {
injectValues(ctxt, builder);
}
Class activeView = _needViewProcesing ? ctxt.getActiveView() : null ;
final SettableBeanProperty[] props = _orderedProperties;
int i = 0 ;
final int propCount = props.length;
while (true ) {
if (p.nextToken() == JsonToken.END_ARRAY) {
return builder;
}
if (i == propCount) {
break ;
}
SettableBeanProperty prop = props[i];
++i;
if (prop != null ) {
if (activeView == null || prop.visibleInView(activeView)) {
try {
prop.deserializeSetAndReturn(p, ctxt, builder);
} catch (Exception e) {
wrapAndThrow(e, builder, prop.getName(), ctxt);
}
continue ;
}
}
p.skipChildren();
}
if (!_ignoreAllUnknown && ctxt.isEnabled(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)) {
ctxt.reportWrongTokenException(this , JsonToken.END_ARRAY,
"Unexpected JSON value(s); expected at most %d properties (in JSON Array)" ,
propCount);
}
while (p.nextToken() != JsonToken.END_ARRAY) {
p.skipChildren();
}
return builder;
}
@Override
protected final Object _deserializeUsingPropertyBased (final JsonParser p,
final DeserializationContext ctxt)
throws IOException
{
final PropertyBasedCreator creator = _propertyBasedCreator;
PropertyValueBuffer buffer = creator.startBuilding(p, ctxt, _objectIdReader);
final SettableBeanProperty[] props = _orderedProperties;
final int propCount = props.length;
final Class activeView = _needViewProcesing ? ctxt.getActiveView() : null ;
int i = 0 ;
Object builder = null ;
for (; p.nextToken() != JsonToken.END_ARRAY; ++i) {
SettableBeanProperty prop = (i < propCount) ? props[i] : null ;
if (prop == null ) {
p.skipChildren();
continue ;
}
if ((activeView != null ) && !prop.visibleInView(activeView)) {
p.skipChildren();
continue ;
}
if (builder != null ) {
try {
builder = prop.deserializeSetAndReturn(p, ctxt, builder);
} catch (Exception e) {
wrapAndThrow(e, builder, prop.getName(), ctxt);
}
continue ;
}
final String propName = prop.getName();
final SettableBeanProperty creatorProp = creator.findCreatorProperty(propName);
if (buffer.readIdProperty(propName) && creatorProp == null ) {
continue ;
}
if (creatorProp != null ) {
if (buffer.assignParameter(creatorProp, creatorProp.deserialize(p, ctxt))) {
try {
builder = creator.build(ctxt, buffer);
} catch (Exception e) {
wrapAndThrow(e, _beanType.getRawClass(), propName, ctxt);
continue ;
}
if (builder.getClass() != _beanType.getRawClass()) {
return ctxt.reportBadDefinition(_beanType, String.format(
"Cannot support implicit polymorphic deserialization for POJOs-as-Arrays style: nominal type %s, actual type %s" ,
ClassUtil.getTypeDescription(_beanType),
builder.getClass().getName()));
}
}
continue ;
}
buffer.bufferProperty(prop, prop.deserialize(p, ctxt));
}
if (builder == null ) {
try {
builder = creator.build(ctxt, buffer);
} catch (Exception e) {
return wrapInstantiationProblem(e, ctxt);
}
}
return builder;
}
protected Object _deserializeFromNonArray (JsonParser p, DeserializationContext ctxt)
throws IOException
{
String message = "Cannot deserialize a POJO (of type %s) from non-Array representation (token: %s): "
+ "type/property designed to be serialized as JSON Array" ;
return ctxt.handleUnexpectedToken(getValueType(ctxt), p.currentToken(), p, message, _beanType.getRawClass().getName(), p.currentToken());
}
}