Skip to content

Commit e08dafe

Browse files
authored
Merge pull request #1574 from jjware/2.8
Fixes #1573
2 parents 934f485 + 7c3b909 commit e08dafe

File tree

2 files changed

+268
-47
lines changed

2 files changed

+268
-47
lines changed

src/main/java/com/fasterxml/jackson/databind/deser/BuilderBasedDeserializer.java

Lines changed: 22 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public class BuilderBasedDeserializer
2626
private static final long serialVersionUID = 1L;
2727

2828
protected final AnnotatedMethod _buildMethod;
29-
29+
3030
/*
3131
/**********************************************************
3232
/* Life-cycle, construction, initialization
@@ -66,7 +66,7 @@ protected BuilderBasedDeserializer(BuilderBasedDeserializer src, boolean ignoreA
6666
super(src, ignoreAllUnknown);
6767
_buildMethod = src._buildMethod;
6868
}
69-
69+
7070
protected BuilderBasedDeserializer(BuilderBasedDeserializer src, NameTransformer unwrapper) {
7171
super(src, unwrapper);
7272
_buildMethod = src._buildMethod;
@@ -86,7 +86,7 @@ public BuilderBasedDeserializer(BuilderBasedDeserializer src, BeanPropertyMap pr
8686
super(src, props);
8787
_buildMethod = src._buildMethod;
8888
}
89-
89+
9090
@Override
9191
public JsonDeserializer<Object> unwrappingDeserializer(NameTransformer unwrapper)
9292
{
@@ -117,13 +117,13 @@ protected BeanDeserializerBase asArrayDeserializer() {
117117
SettableBeanProperty[] props = _beanProperties.getPropertiesInInsertionOrder();
118118
return new BeanAsArrayBuilderDeserializer(this, props, _buildMethod);
119119
}
120-
120+
121121
/*
122122
/**********************************************************
123123
/* JsonDeserializer implementation
124124
/**********************************************************
125125
*/
126-
126+
127127
protected final Object finishBuild(DeserializationContext ctxt, Object builder)
128128
throws IOException
129129
{
@@ -137,7 +137,7 @@ protected final Object finishBuild(DeserializationContext ctxt, Object builder)
137137
return wrapInstantiationProblem(e, ctxt);
138138
}
139139
}
140-
140+
141141
/**
142142
* Main deserialization method for bean-based objects (POJOs).
143143
*/
@@ -146,7 +146,7 @@ public final Object deserialize(JsonParser p, DeserializationContext ctxt)
146146
throws IOException
147147
{
148148
JsonToken t = p.getCurrentToken();
149-
149+
150150
// common case first:
151151
if (t == JsonToken.START_OBJECT) {
152152
t = p.nextToken();
@@ -197,7 +197,7 @@ public Object deserialize(JsonParser p, DeserializationContext ctxt,
197197
*/
198198
return finishBuild(ctxt, _deserialize(p, ctxt, builder));
199199
}
200-
200+
201201
/*
202202
/**********************************************************
203203
/* Concrete deserialization methods
@@ -207,7 +207,7 @@ public Object deserialize(JsonParser p, DeserializationContext ctxt,
207207
protected final Object _deserialize(JsonParser p,
208208
DeserializationContext ctxt, Object builder)
209209
throws IOException, JsonProcessingException
210-
{
210+
{
211211
if (_injectables != null) {
212212
injectValues(ctxt, builder);
213213
}
@@ -233,7 +233,7 @@ protected final Object _deserialize(JsonParser p,
233233
// Skip field name:
234234
p.nextToken();
235235
SettableBeanProperty prop = _beanProperties.find(propName);
236-
236+
237237
if (prop != null) { // normal case
238238
try {
239239
builder = prop.deserializeSetAndReturn(p, ctxt, builder);
@@ -246,7 +246,7 @@ protected final Object _deserialize(JsonParser p,
246246
}
247247
return builder;
248248
}
249-
249+
250250
/**
251251
* Streamlined version that is only used when no "special"
252252
* features are enabled.
@@ -323,7 +323,7 @@ public Object deserializeFromObject(JsonParser p, DeserializationContext ctxt)
323323
* Method called to deserialize bean using "property-based creator":
324324
* this means that a non-default constructor or factory method is
325325
* called, and then possibly other setters. The trick is that
326-
* values for creator method need to be buffered, first; and
326+
* values for creator method need to be buffered, first; and
327327
* due to non-guaranteed ordering possibly some other properties
328328
* as well.
329329
*/
@@ -332,7 +332,7 @@ public Object deserializeFromObject(JsonParser p, DeserializationContext ctxt)
332332
protected final Object _deserializeUsingPropertyBased(final JsonParser p,
333333
final DeserializationContext ctxt)
334334
throws IOException, JsonProcessingException
335-
{
335+
{
336336
final PropertyBasedCreator creator = _propertyBasedCreator;
337337
PropertyValueBuffer buffer = creator.startBuilding(p, ctxt, _objectIdReader);
338338

@@ -414,13 +414,13 @@ protected final Object _deserializeUsingPropertyBased(final JsonParser p,
414414
}
415415
return bean;
416416
}
417-
417+
418418
/*
419419
/**********************************************************
420420
/* Deserializing when we have to consider an active View
421421
/**********************************************************
422422
*/
423-
423+
424424
protected final Object deserializeWithView(JsonParser p, DeserializationContext ctxt,
425425
Object bean, Class<?> activeView)
426426
throws IOException, JsonProcessingException
@@ -447,7 +447,7 @@ protected final Object deserializeWithView(JsonParser p, DeserializationContext
447447
}
448448
return bean;
449449
}
450-
450+
451451
/*
452452
/**********************************************************
453453
/* Handling for cases where we have "unwrapped" values
@@ -477,7 +477,7 @@ protected Object deserializeWithUnwrapped(JsonParser p, DeserializationContext c
477477
}
478478

479479
final Class<?> activeView = _needViewProcesing ? ctxt.getActiveView() : null;
480-
480+
481481
for (; p.getCurrentToken() != JsonToken.END_OBJECT; p.nextToken()) {
482482
String propName = p.getCurrentName();
483483
p.nextToken();
@@ -515,7 +515,7 @@ protected Object deserializeWithUnwrapped(JsonParser p, DeserializationContext c
515515
tokens.writeEndObject();
516516
_unwrappedPropertyHandler.processUnwrapped(p, ctxt, bean, tokens);
517517
return bean;
518-
}
518+
}
519519

520520
@SuppressWarnings("resource")
521521
protected Object deserializeWithUnwrapped(JsonParser p,
@@ -580,31 +580,7 @@ protected Object deserializeUsingPropertyBasedWithUnwrapped(JsonParser p,
580580
// creator property?
581581
SettableBeanProperty creatorProp = creator.findCreatorProperty(propName);
582582
if (creatorProp != null) {
583-
// Last creator property to set?
584-
if (buffer.assignParameter(creatorProp, creatorProp.deserialize(p, ctxt))) {
585-
t = p.nextToken(); // to move to following FIELD_NAME/END_OBJECT
586-
Object bean;
587-
try {
588-
bean = creator.build(ctxt, buffer);
589-
} catch (Exception e) {
590-
wrapAndThrow(e, _beanType.getRawClass(), propName, ctxt);
591-
continue; // never gets here
592-
}
593-
// if so, need to copy all remaining tokens into buffer
594-
while (t == JsonToken.FIELD_NAME) {
595-
p.nextToken(); // to skip name
596-
tokens.copyCurrentStructure(p);
597-
t = p.nextToken();
598-
}
599-
tokens.writeEndObject();
600-
if (bean.getClass() != _beanType.getRawClass()) {
601-
// !!! 08-Jul-2011, tatu: Could probably support; but for now
602-
// it's too complicated, so bail out
603-
ctxt.reportMappingException("Can not create polymorphic instances with unwrapped values");
604-
return null;
605-
}
606-
return _unwrappedPropertyHandler.processUnwrapped(p, ctxt, bean, tokens);
607-
}
583+
buffer.assignParameter(creatorProp, creatorProp.deserialize(p, ctxt));
608584
continue;
609585
}
610586
// Object Id property?
@@ -646,7 +622,7 @@ protected Object deserializeUsingPropertyBasedWithUnwrapped(JsonParser p,
646622
/* external type id
647623
/**********************************************************
648624
*/
649-
625+
650626
protected Object deserializeWithExternalTypeId(JsonParser p, DeserializationContext ctxt)
651627
throws IOException, JsonProcessingException
652628
{
@@ -699,15 +675,14 @@ protected Object deserializeWithExternalTypeId(JsonParser p,
699675
} catch (Exception e) {
700676
wrapAndThrow(e, bean, propName, ctxt);
701677
}
702-
continue;
703678
} else {
704679
// Unknown: let's call handler method
705-
handleUnknownProperty(p, ctxt, bean, propName);
680+
handleUnknownProperty(p, ctxt, bean, propName);
706681
}
707682
}
708683
// and when we get this far, let's try finalizing the deal:
709684
return ext.complete(p, ctxt, bean);
710-
}
685+
}
711686

712687
protected Object deserializeUsingPropertyBasedWithExternalTypeId(JsonParser p,
713688
DeserializationContext ctxt)

0 commit comments

Comments
 (0)