All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.fitbur.fasterxml.jackson.databind.deser.BuilderBasedDeserializer Maven / Gradle / Ivy

There is a newer version: 1.0.0
Show newest version
package com.fitbur.fasterxml.jackson.databind.com.fitburser;

import java.io.IOException;
import java.util.*;

import com.fitbur.fasterxml.jackson.core.*;
import com.fitbur.fasterxml.jackson.databind.*;
import com.fitbur.fasterxml.jackson.databind.com.fitburser.impl.*;
import com.fitbur.fasterxml.jackson.databind.introspect.AnnotatedMethod;
import com.fitbur.fasterxml.jackson.databind.util.NameTransformer;
import com.fitbur.fasterxml.jackson.databind.util.TokenBuffer;

/**
 * Class that handles com.fitburserialization using a separate
 * Builder class, which is used for data binding and
 * produces actual com.fitburserialized value at the end
 * of data binding.
 *

* Note on implementation: much of code has been copied from * {@link BeanDeserializer}; there may be opportunities to * refactor this in future. */ public class BuilderBasedDeserializer extends BeanDeserializerBase { private static final long serialVersionUID = 1L; protected final AnnotatedMethod _buildMethod; /* /********************************************************** /* Life-cycle, construction, initialization /********************************************************** */ /** * Constructor used by {@link BeanDeserializerBuilder}. */ public BuilderBasedDeserializer(BeanDeserializerBuilder builder, BeanDescription beanDesc, BeanPropertyMap properties, Map backRefs, HashSet ignorableProps, boolean ignoreAllUnknown, boolean hasViews) { super(builder, beanDesc, properties, backRefs, ignorableProps, ignoreAllUnknown, hasViews); _buildMethod = builder.getBuildMethod(); // 05-Mar-2012, tatu: Can not really make Object Ids work with builders, not yet anyway if (_objectIdReader != null) { throw new IllegalArgumentException("Can not use Object Id with Builder-based com.fitburserialization (type " +beanDesc.getType()+")"); } } /** * Copy-constructor that can be used by sub-classes to allow * copy-on-write styling copying of settings of an existing instance. */ protected BuilderBasedDeserializer(BuilderBasedDeserializer src) { this(src, src._ignoreAllUnknown); } protected BuilderBasedDeserializer(BuilderBasedDeserializer src, boolean ignoreAllUnknown) { super(src, ignoreAllUnknown); _buildMethod = src._buildMethod; } protected BuilderBasedDeserializer(BuilderBasedDeserializer src, NameTransformer unwrapper) { super(src, unwrapper); _buildMethod = src._buildMethod; } public BuilderBasedDeserializer(BuilderBasedDeserializer src, ObjectIdReader oir) { super(src, oir); _buildMethod = src._buildMethod; } public BuilderBasedDeserializer(BuilderBasedDeserializer src, HashSet ignorableProps) { super(src, ignorableProps); _buildMethod = src._buildMethod; } @Override public JsonDeserializer 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 BuilderBasedDeserializer withObjectIdReader(ObjectIdReader oir) { return new BuilderBasedDeserializer(this, oir); } @Override public BuilderBasedDeserializer withIgnorableProperties(HashSet ignorableProps) { return new BuilderBasedDeserializer(this, ignorableProps); } @Override protected BeanAsArrayBuilderDeserializer asArrayDeserializer() { SettableBeanProperty[] props = _beanProperties.getPropertiesInInsertionOrder(); return new BeanAsArrayBuilderDeserializer(this, props, _buildMethod); } /* /********************************************************** /* JsonDeserializer implementation /********************************************************** */ protected final Object finishBuild(DeserializationContext ctxt, Object builder) throws IOException { try { return _buildMethod.getMember().invoke(builder); } catch (Exception e) { wrapInstantiationProblem(e, ctxt); return null; } } /** * Main com.fitburserialization method for bean-based objects (POJOs). */ @Override public final Object com.fitburserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { JsonToken t = jp.getCurrentToken(); // com.fitburmon case first: if (t == JsonToken.START_OBJECT) { t = jp.nextToken(); if (_vanillaProcessing) { return finishBuild(ctxt, vanillaDeserialize(jp, ctxt, t)); } Object builder = com.fitburserializeFromObject(jp, ctxt); return finishBuild(ctxt, builder); } // and then others, generally requiring use of @JsonCreator switch (t) { case VALUE_STRING: return finishBuild(ctxt, com.fitburserializeFromString(jp, ctxt)); case VALUE_NUMBER_INT: return finishBuild(ctxt, com.fitburserializeFromNumber(jp, ctxt)); case VALUE_NUMBER_FLOAT: return finishBuild(ctxt, com.fitburserializeFromDouble(jp, ctxt)); case VALUE_EMBEDDED_OBJECT: return jp.getEmbeddedObject(); case VALUE_TRUE: case VALUE_FALSE: return finishBuild(ctxt, com.fitburserializeFromBoolean(jp, ctxt)); case START_ARRAY: // these only work if there's a (com.fitburlegating) creator... return finishBuild(ctxt, com.fitburserializeFromArray(jp, ctxt)); case FIELD_NAME: case END_OBJECT: // added to resolve [JACKSON-319], possible related issues return finishBuild(ctxt, com.fitburserializeFromObject(jp, ctxt)); } throw ctxt.mappingException(getBeanClass()); } /** * Secondary com.fitburserialization method, called in cases where POJO * instance is created as part of com.fitburserialization, potentially * after collecting some or all of the properties to set. */ @Override public Object com.fitburserialize(JsonParser jp, DeserializationContext ctxt, Object builder) throws IOException, JsonProcessingException { /* Important: we call separate method which does NOT call * 'finishBuild()', to avoid problems with recursion */ return finishBuild(ctxt, _deserialize(jp, ctxt, builder)); } /* /********************************************************** /* Concrete com.fitburserialization methods /********************************************************** */ protected final Object _deserialize(JsonParser jp, DeserializationContext ctxt, Object builder) throws IOException, JsonProcessingException { if (_injectables != null) { injectValues(ctxt, builder); } if (_unwrappedPropertyHandler != null) { return com.fitburserializeWithUnwrapped(jp, ctxt, builder); } if (_externalTypeIdHandler != null) { return com.fitburserializeWithExternalTypeId(jp, ctxt, builder); } if (_needViewProcesing) { Class view = ctxt.getActiveView(); if (view != null) { return com.fitburserializeWithView(jp, ctxt, builder, view); } } JsonToken t = jp.getCurrentToken(); // 23-Mar-2010, tatu: In some cases, we start with full JSON object too... if (t == JsonToken.START_OBJECT) { t = jp.nextToken(); } for (; t == JsonToken.FIELD_NAME; t = jp.nextToken()) { String propName = jp.getCurrentName(); // Skip field name: jp.nextToken(); SettableBeanProperty prop = _beanProperties.find(propName); if (prop != null) { // normal case try { builder = prop.com.fitburserializeSetAndReturn(jp, ctxt, builder); } catch (Exception e) { wrapAndThrow(e, builder, propName, ctxt); } continue; } if (_ignorableProps != null && _ignorableProps.contains(propName)) { jp.skipChildren(); } else if (_anySetter != null) { // should we try to get return value of any setter too? _anySetter.com.fitburserializeAndSet(jp, ctxt, builder, propName); continue; } else { // Unknown: let's call handler method handleUnknownProperty(jp, ctxt, builder, propName); } } return builder; } /** * Streamlined version that is only used when no "special" * features are enabled. */ private final Object vanillaDeserialize(JsonParser jp, DeserializationContext ctxt, JsonToken t) throws IOException, JsonProcessingException { Object bean = _valueInstantiator.createUsingDefault(ctxt); for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) { String propName = jp.getCurrentName(); // Skip field name: jp.nextToken(); SettableBeanProperty prop = _beanProperties.find(propName); if (prop != null) { // normal case try { bean = prop.com.fitburserializeSetAndReturn(jp, ctxt, bean); } catch (Exception e) { wrapAndThrow(e, bean, propName, ctxt); } } else { _vanillaDeserializeHandleUnknown(jp, ctxt, bean, propName); } } return bean; } /** * Helper method called for an unknown property, when using "vanilla" * processing. */ private final void _vanillaDeserializeHandleUnknown(JsonParser jp, DeserializationContext ctxt, Object bean, String propName) throws IOException, JsonProcessingException { if (_ignorableProps != null && _ignorableProps.contains(propName)) { jp.skipChildren(); } else if (_anySetter != null) { try { // should we consider return type of any setter? _anySetter.com.fitburserializeAndSet(jp, ctxt, bean, propName); } catch (Exception e) { wrapAndThrow(e, bean, propName, ctxt); } } else { // Unknown: let's call handler method handleUnknownProperty(jp, ctxt, bean, propName); } } /** * General version used when handling needs more advanced * features. */ public Object com.fitburserializeFromObject(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { if (_nonStandardCreation) { if (_unwrappedPropertyHandler != null) { return com.fitburserializeWithUnwrapped(jp, ctxt); } if (_externalTypeIdHandler != null) { return com.fitburserializeWithExternalTypeId(jp, ctxt); } return com.fitburserializeFromObjectUsingNonDefault(jp, ctxt); } Object bean = _valueInstantiator.createUsingDefault(ctxt); if (_injectables != null) { injectValues(ctxt, bean); } if (_needViewProcesing) { Class view = ctxt.getActiveView(); if (view != null) { return com.fitburserializeWithView(jp, ctxt, bean, view); } } for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) { String propName = jp.getCurrentName(); // Skip field name: jp.nextToken(); SettableBeanProperty prop = _beanProperties.find(propName); if (prop != null) { // normal case try { bean = prop.com.fitburserializeSetAndReturn(jp, ctxt, bean); } catch (Exception e) { wrapAndThrow(e, bean, propName, ctxt); } continue; } /* As per [JACKSON-313], things marked as ignorable should not be * passed to any setter */ if (_ignorableProps != null && _ignorableProps.contains(propName)) { jp.skipChildren(); } else if (_anySetter != null) { try { _anySetter.com.fitburserializeAndSet(jp, ctxt, bean, propName); } catch (Exception e) { wrapAndThrow(e, bean, propName, ctxt); } continue; } else { // Unknown: let's call handler method handleUnknownProperty(jp, ctxt, bean, propName); } } return bean; } protected Object com.fitburserializeFromObjectUsingNonDefault(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { if (_delegateDeserializer != null) { return _valueInstantiator.createUsingDelegate(ctxt, _delegateDeserializer.com.fitburserialize(jp, ctxt)); } if (_propertyBasedCreator != null) { return _deserializeUsingPropertyBased(jp, ctxt); } // should only occur for abstract types... 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?)"); } public Object com.fitburserializeFromString(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { // First things first: id Object Id is used, most likely that's it if (_objectIdReader != null) { return com.fitburserializeFromObjectId(jp, ctxt); } /* Bit com.fitburplicated if we have com.fitburlegating creator; may need to use it, * or might not... */ if (_delegateDeserializer != null) { if (!_valueInstantiator.canCreateFromString()) { Object bean = _valueInstantiator.createUsingDelegate(ctxt, _delegateDeserializer.com.fitburserialize(jp, ctxt)); if (_injectables != null) { injectValues(ctxt, bean); } return bean; } } return _valueInstantiator.createFromString(ctxt, jp.getText()); } public Object com.fitburserializeFromNumber(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { // First things first: id Object Id is used, most likely that's it if (_objectIdReader != null) { return com.fitburserializeFromObjectId(jp, ctxt); } switch (jp.getNumberType()) { case INT: if (_delegateDeserializer != null) { if (!_valueInstantiator.canCreateFromInt()) { Object bean = _valueInstantiator.createUsingDelegate(ctxt, _delegateDeserializer.com.fitburserialize(jp, ctxt)); if (_injectables != null) { injectValues(ctxt, bean); } return bean; } } return _valueInstantiator.createFromInt(ctxt, jp.getIntValue()); case LONG: if (_delegateDeserializer != null) { if (!_valueInstantiator.canCreateFromInt()) { Object bean = _valueInstantiator.createUsingDelegate(ctxt, _delegateDeserializer.com.fitburserialize(jp, ctxt)); if (_injectables != null) { injectValues(ctxt, bean); } return bean; } } return _valueInstantiator.createFromLong(ctxt, jp.getLongValue()); } // actually, could also be BigInteger, so: if (_delegateDeserializer != null) { Object bean = _valueInstantiator.createUsingDelegate(ctxt, _delegateDeserializer.com.fitburserialize(jp, ctxt)); if (_injectables != null) { injectValues(ctxt, bean); } return bean; } throw ctxt.instantiationException(getBeanClass(), "no suitable creator method found to com.fitburserialize from JSON integer number"); } /** * Method called to com.fitburserialize POJO value from a JSON floating-point * number. */ public Object com.fitburserializeFromDouble(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { switch (jp.getNumberType()) { case FLOAT: // no separate methods for taking float... case DOUBLE: if (_delegateDeserializer != null) { if (!_valueInstantiator.canCreateFromDouble()) { Object bean = _valueInstantiator.createUsingDelegate(ctxt, _delegateDeserializer.com.fitburserialize(jp, ctxt)); if (_injectables != null) { injectValues(ctxt, bean); } return bean; } } return _valueInstantiator.createFromDouble(ctxt, jp.getDoubleValue()); } // actually, could also be BigDecimal, so: if (_delegateDeserializer != null) { return _valueInstantiator.createUsingDelegate(ctxt, _delegateDeserializer.com.fitburserialize(jp, ctxt)); } throw ctxt.instantiationException(getBeanClass(), "no suitable creator method found to com.fitburserialize from JSON floating-point number"); } /** * Method called to com.fitburserialize POJO value from a JSON boolean value (true, false) */ public Object com.fitburserializeFromBoolean(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { if (_delegateDeserializer != null) { if (!_valueInstantiator.canCreateFromBoolean()) { Object bean = _valueInstantiator.createUsingDelegate(ctxt, _delegateDeserializer.com.fitburserialize(jp, ctxt)); if (_injectables != null) { injectValues(ctxt, bean); } return bean; } } boolean value = (jp.getCurrentToken() == JsonToken.VALUE_TRUE); return _valueInstantiator.createFromBoolean(ctxt, value); } public Object com.fitburserializeFromArray(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { if (_delegateDeserializer != null) { try { Object bean = _valueInstantiator.createUsingDelegate(ctxt, _delegateDeserializer.com.fitburserialize(jp, ctxt)); if (_injectables != null) { injectValues(ctxt, bean); } return bean; } catch (Exception e) { wrapInstantiationProblem(e, ctxt); } } throw ctxt.mappingException(getBeanClass()); } /** * Method called to com.fitburserialize bean using "property-based creator": * this means that a non-com.fitburfault constructor or factory method is * called, and then possibly other setters. The trick is that * values for creator method need to be buffered, first; and * due to non-guaranteed ordering possibly some other properties * as well. */ protected final Object _deserializeUsingPropertyBased(final JsonParser jp, final DeserializationContext ctxt) throws IOException, JsonProcessingException { final PropertyBasedCreator creator = _propertyBasedCreator; PropertyValueBuffer buffer = creator.startBuilding(jp, ctxt, _objectIdReader); // 04-Jan-2010, tatu: May need to collect unknown properties for polymorphic cases TokenBuffer unknown = null; JsonToken t = jp.getCurrentToken(); for (; t == JsonToken.FIELD_NAME; t = jp.nextToken()) { String propName = jp.getCurrentName(); jp.nextToken(); // to point to value // creator property? SettableBeanProperty creatorProp = creator.findCreatorProperty(propName); if (creatorProp != null) { // Last creator property to set? Object value = creatorProp.com.fitburserialize(jp, ctxt); if (buffer.assignParameter(creatorProp.getCreatorIndex(), value)) { jp.nextToken(); // to move to following FIELD_NAME/END_OBJECT Object bean; try { bean = creator.build(ctxt, buffer); } catch (Exception e) { wrapAndThrow(e, _beanType.getRawClass(), propName, ctxt); continue; // never gets here } // polymorphic? if (bean.getClass() != _beanType.getRawClass()) { return handlePolymorphic(jp, ctxt, bean, unknown); } if (unknown != null) { // nope, just extra unknown stuff... bean = handleUnknownProperties(ctxt, bean, unknown); } // or just clean? return _deserialize(jp, ctxt, bean); } continue; } // Object Id property? if (buffer.readIdProperty(propName)) { continue; } // regular property? needs buffering SettableBeanProperty prop = _beanProperties.find(propName); if (prop != null) { buffer.bufferProperty(prop, prop.com.fitburserialize(jp, ctxt)); continue; } /* As per [JACKSON-313], things marked as ignorable should not be * passed to any setter */ if (_ignorableProps != null && _ignorableProps.contains(propName)) { jp.skipChildren(); continue; } // "any property"? if (_anySetter != null) { buffer.bufferAnyProperty(_anySetter, propName, _anySetter.com.fitburserialize(jp, ctxt)); continue; } // Ok then, let's collect the whole field; name and value if (unknown == null) { unknown = new TokenBuffer(jp.getCodec()); } unknown.writeFieldName(propName); unknown.copyCurrentStructure(jp); } // We hit END_OBJECT, so: Object bean; try { bean = creator.build(ctxt, buffer); } catch (Exception e) { wrapInstantiationProblem(e, ctxt); return null; // never gets here } if (unknown != null) { // polymorphic? if (bean.getClass() != _beanType.getRawClass()) { return handlePolymorphic(null, ctxt, bean, unknown); } // no, just some extra unknown properties return handleUnknownProperties(ctxt, bean, unknown); } return bean; } /** * Method called in cases where we may have polymorphic com.fitburserialization * case: that is, type of Creator-constructed bean is not the type * of com.fitburserializer itself. It should be a sub-class or implementation * class; either way, we may have more specific com.fitburserializer to use * for handling it. * * @param jp (optional) If not null, parser that has more properties to handle * (in addition to buffered properties); if null, all properties are passed * in buffer */ protected Object handlePolymorphic(JsonParser jp, DeserializationContext ctxt, Object bean, TokenBuffer unknownTokens) throws IOException, JsonProcessingException { // First things first: maybe there is a more specific com.fitburserializer available? JsonDeserializer subDeser = _findSubclassDeserializer(ctxt, bean, unknownTokens); if (subDeser != null) { if (unknownTokens != null) { // need to add END_OBJECT marker first unknownTokens.writeEndObject(); JsonParser p2 = unknownTokens.asParser(); p2.nextToken(); // to get to first data field bean = subDeser.com.fitburserialize(p2, ctxt, bean); } // Original parser may also have some leftovers if (jp != null) { bean = subDeser.com.fitburserialize(jp, ctxt, bean); } return bean; } // nope; need to use this com.fitburserializer. Unknowns we've seen so far? if (unknownTokens != null) { bean = handleUnknownProperties(ctxt, bean, unknownTokens); } // and/or things left to process via main parser? if (jp != null) { bean = com.fitburserialize(jp, ctxt, bean); } return bean; } /* /********************************************************** /* Deserializing when we have to consider an active View /********************************************************** */ protected final Object com.fitburserializeWithView(JsonParser jp, DeserializationContext ctxt, Object bean, Class activeView) throws IOException, JsonProcessingException { JsonToken t = jp.getCurrentToken(); for (; t == JsonToken.FIELD_NAME; t = jp.nextToken()) { String propName = jp.getCurrentName(); // Skip field name: jp.nextToken(); SettableBeanProperty prop = _beanProperties.find(propName); if (prop != null) { if (!prop.visibleInView(activeView)) { jp.skipChildren(); continue; } try { bean = prop.com.fitburserializeSetAndReturn(jp, ctxt, bean); } catch (Exception e) { wrapAndThrow(e, bean, propName, ctxt); } continue; } /* As per [JACKSON-313], things marked as ignorable should not be * passed to any setter */ if (_ignorableProps != null && _ignorableProps.contains(propName)) { jp.skipChildren(); } else if (_anySetter != null) { _anySetter.com.fitburserializeAndSet(jp, ctxt, bean, propName); continue; } else { // Unknown: let's call handler method handleUnknownProperty(jp, ctxt, bean, propName); } } return bean; } /* /********************************************************** /* Handling for cases where we have "unwrapped" values /********************************************************** */ /** * Method called when there are com.fitburclared "unwrapped" properties * which need special handling */ protected Object com.fitburserializeWithUnwrapped(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { if (_delegateDeserializer != null) { return _valueInstantiator.createUsingDelegate(ctxt, _delegateDeserializer.com.fitburserialize(jp, ctxt)); } if (_propertyBasedCreator != null) { return com.fitburserializeUsingPropertyBasedWithUnwrapped(jp, ctxt); } TokenBuffer tokens = new TokenBuffer(jp.getCodec()); tokens.writeStartObject(); Object bean = _valueInstantiator.createUsingDefault(ctxt); if (_injectables != null) { injectValues(ctxt, bean); } final Class activeView = _needViewProcesing ? ctxt.getActiveView() : null; for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) { String propName = jp.getCurrentName(); jp.nextToken(); SettableBeanProperty prop = _beanProperties.find(propName); if (prop != null) { // normal case if (activeView != null && !prop.visibleInView(activeView)) { jp.skipChildren(); continue; } try { bean = prop.com.fitburserializeSetAndReturn(jp, ctxt, bean); } catch (Exception e) { wrapAndThrow(e, bean, propName, ctxt); } continue; } // ignorable things should be ignored if (_ignorableProps != null && _ignorableProps.contains(propName)) { jp.skipChildren(); continue; } // but... others should be passed to unwrapped property com.fitburserializers tokens.writeFieldName(propName); tokens.copyCurrentStructure(jp); // how about any setter? We'll get copies but... if (_anySetter != null) { try { _anySetter.com.fitburserializeAndSet(jp, ctxt, bean, propName); } catch (Exception e) { wrapAndThrow(e, bean, propName, ctxt); } continue; } } tokens.writeEndObject(); _unwrappedPropertyHandler.processUnwrapped(jp, ctxt, bean, tokens); return bean; } protected Object com.fitburserializeWithUnwrapped(JsonParser jp, DeserializationContext ctxt, Object bean) throws IOException, JsonProcessingException { JsonToken t = jp.getCurrentToken(); if (t == JsonToken.START_OBJECT) { t = jp.nextToken(); } TokenBuffer tokens = new TokenBuffer(jp.getCodec()); tokens.writeStartObject(); final Class activeView = _needViewProcesing ? ctxt.getActiveView() : null; for (; t == JsonToken.FIELD_NAME; t = jp.nextToken()) { String propName = jp.getCurrentName(); SettableBeanProperty prop = _beanProperties.find(propName); jp.nextToken(); if (prop != null) { // normal case if (activeView != null && !prop.visibleInView(activeView)) { jp.skipChildren(); continue; } try { bean = prop.com.fitburserializeSetAndReturn(jp, ctxt, bean); } catch (Exception e) { wrapAndThrow(e, bean, propName, ctxt); } continue; } if (_ignorableProps != null && _ignorableProps.contains(propName)) { jp.skipChildren(); continue; } // but... others should be passed to unwrapped property com.fitburserializers tokens.writeFieldName(propName); tokens.copyCurrentStructure(jp); // how about any setter? We'll get copies but... if (_anySetter != null) { _anySetter.com.fitburserializeAndSet(jp, ctxt, bean, propName); } } tokens.writeEndObject(); _unwrappedPropertyHandler.processUnwrapped(jp, ctxt, bean, tokens); return bean; } protected Object com.fitburserializeUsingPropertyBasedWithUnwrapped(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { final PropertyBasedCreator creator = _propertyBasedCreator; PropertyValueBuffer buffer = creator.startBuilding(jp, ctxt, _objectIdReader); TokenBuffer tokens = new TokenBuffer(jp.getCodec()); tokens.writeStartObject(); JsonToken t = jp.getCurrentToken(); for (; t == JsonToken.FIELD_NAME; t = jp.nextToken()) { String propName = jp.getCurrentName(); jp.nextToken(); // to point to value // creator property? SettableBeanProperty creatorProp = creator.findCreatorProperty(propName); if (creatorProp != null) { // Last creator property to set? Object value = creatorProp.com.fitburserialize(jp, ctxt); if (buffer.assignParameter(creatorProp.getCreatorIndex(), value)) { t = jp.nextToken(); // to move to following FIELD_NAME/END_OBJECT Object bean; try { bean = creator.build(ctxt, buffer); } catch (Exception e) { wrapAndThrow(e, _beanType.getRawClass(), propName, ctxt); continue; // never gets here } // if so, need to copy all remaining tokens into buffer while (t == JsonToken.FIELD_NAME) { jp.nextToken(); // to skip name tokens.copyCurrentStructure(jp); t = jp.nextToken(); } tokens.writeEndObject(); if (bean.getClass() != _beanType.getRawClass()) { // !!! 08-Jul-2011, tatu: Could probably support; but for now // it's too com.fitburplicated, so bail out throw ctxt.mappingException("Can not create polymorphic instances with unwrapped values"); } return _unwrappedPropertyHandler.processUnwrapped(jp, ctxt, bean, tokens); } continue; } // Object Id property? if (buffer.readIdProperty(propName)) { continue; } // regular property? needs buffering SettableBeanProperty prop = _beanProperties.find(propName); if (prop != null) { buffer.bufferProperty(prop, prop.com.fitburserialize(jp, ctxt)); continue; } /* As per [JACKSON-313], things marked as ignorable should not be * passed to any setter */ if (_ignorableProps != null && _ignorableProps.contains(propName)) { jp.skipChildren(); continue; } tokens.writeFieldName(propName); tokens.copyCurrentStructure(jp); // "any property"? if (_anySetter != null) { buffer.bufferAnyProperty(_anySetter, propName, _anySetter.com.fitburserialize(jp, ctxt)); } } // We hit END_OBJECT, so: Object bean; // !!! 15-Feb-2012, tatu: Need to modify creator to use Builder! try { bean = creator.build(ctxt, buffer); } catch (Exception e) { wrapInstantiationProblem(e, ctxt); return null; // never gets here } return _unwrappedPropertyHandler.processUnwrapped(jp, ctxt, bean, tokens); } /* /********************************************************** /* Handling for cases where we have property/-ies with /* external type id /********************************************************** */ protected Object com.fitburserializeWithExternalTypeId(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { if (_propertyBasedCreator != null) { return com.fitburserializeUsingPropertyBasedWithExternalTypeId(jp, ctxt); } return com.fitburserializeWithExternalTypeId(jp, ctxt, _valueInstantiator.createUsingDefault(ctxt)); } protected Object com.fitburserializeWithExternalTypeId(JsonParser jp, DeserializationContext ctxt, Object bean) throws IOException, JsonProcessingException { final Class activeView = _needViewProcesing ? ctxt.getActiveView() : null; final ExternalTypeHandler ext = _externalTypeIdHandler.start(); for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) { String propName = jp.getCurrentName(); jp.nextToken(); SettableBeanProperty prop = _beanProperties.find(propName); if (prop != null) { // normal case if (activeView != null && !prop.visibleInView(activeView)) { jp.skipChildren(); continue; } try { bean = prop.com.fitburserializeSetAndReturn(jp, ctxt, bean); } catch (Exception e) { wrapAndThrow(e, bean, propName, ctxt); } continue; } // ignorable things should be ignored if (_ignorableProps != null && _ignorableProps.contains(propName)) { jp.skipChildren(); continue; } // but others are likely to be part of external type id thingy... if (ext.handlePropertyValue(jp, ctxt, propName, bean)) { continue; } // if not, the usual fallback handling: if (_anySetter != null) { try { _anySetter.com.fitburserializeAndSet(jp, ctxt, bean, propName); } catch (Exception e) { wrapAndThrow(e, bean, propName, ctxt); } continue; } else { // Unknown: let's call handler method handleUnknownProperty(jp, ctxt, bean, propName); } } // and when we get this far, let's try finalizing the com.fitbural: return ext.com.fitburplete(jp, ctxt, bean); } protected Object com.fitburserializeUsingPropertyBasedWithExternalTypeId(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { // !!! 04-Mar-2012, TODO: Need to fix -- will not work as is... throw new IllegalStateException("Deserialization with Builder, External type id, @JsonCreator not yet implemented"); } }