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
package com.fasterxml.jackson.databind.deser.impl;
import java.io.IOException;
import java.util.HashSet;
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.NameTransformer;
public class BeanAsArrayBuilderDeserializer
extends BeanDeserializerBase
{
private static final long serialVersionUID = 1L ;
final protected BeanDeserializerBase _delegate;
final protected SettableBeanProperty[] _orderedProperties;
final protected AnnotatedMethod _buildMethod;
public BeanAsArrayBuilderDeserializer (BeanDeserializerBase delegate,
SettableBeanProperty[] ordered,
AnnotatedMethod buildMethod)
{
super (delegate);
_delegate = delegate;
_orderedProperties = ordered;
_buildMethod = buildMethod;
}
@Override
public JsonDeserializer unwrappingDeserializer (NameTransformer unwrapper)
{
return _delegate.unwrappingDeserializer(unwrapper);
}
@Override
public BeanAsArrayBuilderDeserializer withObjectIdReader (ObjectIdReader oir) {
return new BeanAsArrayBuilderDeserializer(_delegate.withObjectIdReader(oir),
_orderedProperties, _buildMethod);
}
@Override
public BeanAsArrayBuilderDeserializer withIgnorableProperties (HashSet ignorableProps) {
return new BeanAsArrayBuilderDeserializer(_delegate.withIgnorableProperties(ignorableProps),
_orderedProperties, _buildMethod);
}
@Override
protected BeanAsArrayBuilderDeserializer asArrayDeserializer () {
return this ;
}
protected final Object finishBuild (DeserializationContext ctxt, Object builder)
throws IOException
{
try {
return _buildMethod.getMember().invoke(builder);
} catch (Exception e) {
wrapInstantiationProblem(e, ctxt);
return null ;
}
}
@Override
public Object deserialize (JsonParser jp, DeserializationContext ctxt)
throws IOException, JsonProcessingException
{
if (jp.getCurrentToken() != JsonToken.START_ARRAY) {
return finishBuild(ctxt, _deserializeFromNonArray(jp, ctxt));
}
if (!_vanillaProcessing) {
return finishBuild(ctxt, _deserializeNonVanilla(jp, ctxt));
}
Object builder = _valueInstantiator.createUsingDefault(ctxt);
final SettableBeanProperty[] props = _orderedProperties;
int i = 0 ;
final int propCount = props.length;
while (true ) {
if (jp.nextToken() == JsonToken.END_ARRAY) {
return finishBuild(ctxt, builder);
}
if (i == propCount) {
break ;
}
SettableBeanProperty prop = props[i];
if (prop != null ) {
try {
builder = prop.deserializeSetAndReturn(jp, ctxt, builder);
} catch (Exception e) {
wrapAndThrow(e, builder, prop.getName(), ctxt);
}
} else {
jp.skipChildren();
}
++i;
}
if (!_ignoreAllUnknown) {
throw ctxt.mappingException("Unexpected JSON values; expected at most " +propCount+" properties (in JSON Array)" );
}
while (jp.nextToken() != JsonToken.END_ARRAY) {
jp.skipChildren();
}
return finishBuild(ctxt, builder);
}
@Override
public Object deserialize (JsonParser jp, DeserializationContext ctxt, Object builder)
throws IOException, JsonProcessingException
{
if (_injectables != null ) {
injectValues(ctxt, builder);
}
final SettableBeanProperty[] props = _orderedProperties;
int i = 0 ;
final int propCount = props.length;
while (true ) {
if (jp.nextToken() == JsonToken.END_ARRAY) {
return finishBuild(ctxt, builder);
}
if (i == propCount) {
break ;
}
SettableBeanProperty prop = props[i];
if (prop != null ) {
try {
builder = prop.deserializeSetAndReturn(jp, ctxt, builder);
} catch (Exception e) {
wrapAndThrow(e, builder, prop.getName(), ctxt);
}
} else {
jp.skipChildren();
}
++i;
}
if (!_ignoreAllUnknown) {
throw ctxt.mappingException("Unexpected JSON values; expected at most " +propCount+" properties (in JSON Array)" );
}
while (jp.nextToken() != JsonToken.END_ARRAY) {
jp.skipChildren();
}
return finishBuild(ctxt, builder);
}
@Override
public Object deserializeFromObject (JsonParser jp, DeserializationContext ctxt)
throws IOException, JsonProcessingException
{
return _deserializeFromNonArray(jp, ctxt);
}
protected Object _deserializeNonVanilla (JsonParser jp, DeserializationContext ctxt)
throws IOException, JsonProcessingException
{
if (_nonStandardCreation) {
return _deserializeWithCreator(jp, 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 (jp.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(jp, ctxt, builder);
} catch (Exception e) {
wrapAndThrow(e, builder, prop.getName(), ctxt);
}
continue ;
}
}
jp.skipChildren();
}
if (!_ignoreAllUnknown) {
throw ctxt.mappingException("Unexpected JSON values; expected at most " +propCount+" properties (in JSON Array)" );
}
while (jp.nextToken() != JsonToken.END_ARRAY) {
jp.skipChildren();
}
return builder;
}
protected Object _deserializeWithCreator (JsonParser jp, DeserializationContext ctxt)
throws IOException, JsonProcessingException
{
if (_delegateDeserializer != null ) {
return _valueInstantiator.createUsingDelegate(ctxt,
_delegateDeserializer.deserialize(jp, ctxt));
}
if (_propertyBasedCreator != null ) {
return _deserializeUsingPropertyBased(jp, ctxt);
}
if (_beanType.isAbstract()) {
throw JsonMappingException.from(jp, "Can not instantiate abstract type " +_beanType
+" (need to add/enable type information?)" );
}
throw JsonMappingException.from(jp, "No suitable constructor found for type "
+_beanType+": can not instantiate from JSON object (need to add/enable type information?)" );
}
@Override
protected final Object _deserializeUsingPropertyBased (final JsonParser jp,
final DeserializationContext ctxt)
throws IOException, JsonProcessingException
{
final PropertyBasedCreator creator = _propertyBasedCreator;
PropertyValueBuffer buffer = creator.startBuilding(jp, ctxt, _objectIdReader);
final SettableBeanProperty[] props = _orderedProperties;
final int propCount = props.length;
int i = 0 ;
Object builder = null ;
for (; jp.nextToken() != JsonToken.END_ARRAY; ++i) {
SettableBeanProperty prop = (i < propCount) ? props[i] : null ;
if (prop == null ) {
jp.skipChildren();
continue ;
}
if (builder != null ) {
try {
builder = prop.deserializeSetAndReturn(jp, ctxt, builder);
} catch (Exception e) {
wrapAndThrow(e, builder, prop.getName(), ctxt);
}
continue ;
}
final String propName = prop.getName();
SettableBeanProperty creatorProp = creator.findCreatorProperty(propName);
if (creatorProp != null ) {
Object value = creatorProp.deserialize(jp, ctxt);
if (buffer.assignParameter(creatorProp.getCreatorIndex(), value)) {
try {
builder = creator.build(ctxt, buffer);
} catch (Exception e) {
wrapAndThrow(e, _beanType.getRawClass(), propName, ctxt);
continue ;
}
if (builder.getClass() != _beanType.getRawClass()) {
throw ctxt.mappingException("Can not support implicit polymorphic deserialization for POJOs-as-Arrays style: "
+"nominal type " +_beanType.getRawClass().getName()+", actual type " +builder.getClass().getName());
}
}
continue ;
}
if (buffer.readIdProperty(propName)) {
continue ;
}
buffer.bufferProperty(prop, prop.deserialize(jp, ctxt));
}
if (builder == null ) {
try {
builder = creator.build(ctxt, buffer);
} catch (Exception e) {
wrapInstantiationProblem(e, ctxt);
return null ;
}
}
return builder;
}
protected Object _deserializeFromNonArray (JsonParser jp, DeserializationContext ctxt)
throws IOException, JsonProcessingException
{
throw ctxt.mappingException("Can not deserialize a POJO (of type " +_beanType.getRawClass().getName()
+") from non-Array representation (token: " +jp.getCurrentToken()
+"): type/property designed to be serialized as JSON Array" );
}
}