Skip to content

Commit

Permalink
Fixed #349
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Nov 30, 2016
1 parent 152f855 commit d338aa5
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 26 deletions.
2 changes: 2 additions & 0 deletions release-notes/VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Project: jackson-databind

2.8.6 (not yet released)

#349: @JsonAnySetter with @JsonUnwrapped: deserialization fails with arrays
(reported by hdave@github)
#1388: `@JsonIdentityInfo`: id has to be the first key in deserialization when
deserializing with `@JsonCreator`
(reported by moodysalem@github)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -632,13 +632,24 @@ protected Object deserializeWithUnwrapped(JsonParser p, DeserializationContext c
handleIgnoredProperty(p, ctxt, bean, propName);
continue;
}
// but... others should be passed to unwrapped property deserializers
tokens.writeFieldName(propName);
tokens.copyCurrentStructure(p);
// 29-Nov-2016, tatu: probably should try to avoid sending content
// both to any setter AND buffer... but, for now, the only thing
// we can do.
// how about any setter? We'll get copies but...
if (_anySetter != null) {
if (_anySetter == null) {
// but... others should be passed to unwrapped property deserializers
tokens.writeFieldName(propName);
tokens.copyCurrentStructure(p);
} else {
// Need to copy to a separate buffer first
TokenBuffer b2 = new TokenBuffer(p, ctxt);
b2.copyCurrentStructure(p);
tokens.writeFieldName(propName);
tokens.append(b2);
try {
_anySetter.deserializeAndSet(p, ctxt, bean, propName);
JsonParser p2 = b2.asParser(p);
p2.nextToken();
_anySetter.deserializeAndSet(p2, ctxt, bean, propName);
} catch (Exception e) {
wrapAndThrow(e, bean, propName, ctxt);
}
Expand Down Expand Up @@ -681,12 +692,28 @@ protected Object deserializeWithUnwrapped(JsonParser p, DeserializationContext c
handleIgnoredProperty(p, ctxt, bean, propName);
continue;
}
// but... others should be passed to unwrapped property deserializers
tokens.writeFieldName(propName);
tokens.copyCurrentStructure(p);
// 29-Nov-2016, tatu: probably should try to avoid sending content
// both to any setter AND buffer... but, for now, the only thing
// we can do.
// how about any setter? We'll get copies but...
if (_anySetter != null) {
_anySetter.deserializeAndSet(p, ctxt, bean, propName);
if (_anySetter == null) {
// but... others should be passed to unwrapped property deserializers
tokens.writeFieldName(propName);
tokens.copyCurrentStructure(p);
} else {
// Need to copy to a separate buffer first
TokenBuffer b2 = new TokenBuffer(p, ctxt);
b2.copyCurrentStructure(p);
tokens.writeFieldName(propName);
tokens.append(b2);
try {
JsonParser p2 = b2.asParser(p);
p2.nextToken();
_anySetter.deserializeAndSet(p2, ctxt, bean, propName);
} catch (Exception e) {
wrapAndThrow(e, bean, propName, ctxt);
}
continue;
}
}
tokens.writeEndObject();
Expand Down Expand Up @@ -755,15 +782,29 @@ protected Object deserializeUsingPropertyBasedWithUnwrapped(JsonParser p, Deseri
handleIgnoredProperty(p, ctxt, handledType(), propName);
continue;
}
tokens.writeFieldName(propName);
tokens.copyCurrentStructure(p);
// "any property"?
if (_anySetter != null) {
// 29-Nov-2016, tatu: probably should try to avoid sending content
// both to any setter AND buffer... but, for now, the only thing
// we can do.
// how about any setter? We'll get copies but...
if (_anySetter == null) {
// but... others should be passed to unwrapped property deserializers
tokens.writeFieldName(propName);
tokens.copyCurrentStructure(p);
} else {
// Need to copy to a separate buffer first
TokenBuffer b2 = new TokenBuffer(p, ctxt);
b2.copyCurrentStructure(p);
tokens.writeFieldName(propName);
tokens.append(b2);
try {
buffer.bufferAnyProperty(_anySetter, propName, _anySetter.deserialize(p, ctxt));
JsonParser p2 = b2.asParser(p);
p2.nextToken();
buffer.bufferAnyProperty(_anySetter, propName,
_anySetter.deserialize(p2, ctxt));
} catch (Exception e) {
wrapAndThrow(e, _beanType.getRawClass(), propName, ctxt);
}
continue;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ public UnwrappedPropertyHandler renameAll(NameTransformer transformer)
}

@SuppressWarnings("resource")
public Object processUnwrapped(JsonParser originalParser, DeserializationContext ctxt, Object bean,
TokenBuffer buffered)
throws IOException, JsonProcessingException
public Object processUnwrapped(JsonParser originalParser, DeserializationContext ctxt,
Object bean, TokenBuffer buffered)
throws IOException
{
for (int i = 0, len = _properties.size(); i < len; ++i) {
SettableBeanProperty prop = _properties.get(i);
JsonParser jp = buffered.asParser();
jp.nextToken();
prop.deserializeAndSet(jp, ctxt, bean);
JsonParser p = buffered.asParser();
p.nextToken();
prop.deserializeAndSet(p, ctxt, bean);
}
return bean;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.fasterxml.jackson.failing;
package com.fasterxml.jackson.databind.deser;

import java.util.*;

Expand Down Expand Up @@ -26,7 +26,7 @@ public Map<String, Object> getProperties() {
}

@JsonUnwrapped
public IdentityDTO349 identity = null;
public IdentityDTO349 identity;
}

static class IdentityDTO349 {
Expand All @@ -38,9 +38,9 @@ public void testUnwrappedWithAny() throws Exception
final ObjectMapper mapper = objectMapper();
final String json = aposToQuotes(
"{ 'type' : 'IST',\n"
+" 'spacename' : 'Foo Models',\n"
+" 'name' : 'BLAH-New',\n"
+" 'description' : 'namespace.name: X THIN FIR.DR-WD12-New',\n"
//+" 'spacename' : 'Foo Models',\n"
//+" 'name' : 'BLAH-New',\n"
//+" 'description' : 'namespace.name: X THIN FIR.DR-WD12-New',\n"
+" 'ZoomLinks': [ 'foofoofoofoo', 'barbarbarbar' ] }"
);
Bean349 value = mapper.readValue(json, Bean349.class);
Expand Down

0 comments on commit d338aa5

Please sign in to comment.