Skip to content

Commit

Permalink
Fix #1978
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Mar 22, 2018
1 parent ba35c17 commit 277151d
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 4 deletions.
5 changes: 5 additions & 0 deletions release-notes/CREDITS-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -762,3 +762,8 @@ Aniruddha Maru (maroux@github)
Timur Shakurov (saladinkzn@github)
* Reported #1947: `MapperFeature.AUTO_DETECT_XXX` do not work if all disabled
(2.9.5)
roeltje25@github
* Reported #1978: Using @JsonUnwrapped annotation in builderdeserializer hangs in
infinite loop
(2.9.5)
2 changes: 2 additions & 0 deletions release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ Project: jackson-databind
(reported by Timur S)
#1977: Serializing an Iterator with multiple sub-types fails after upgrading to 2.9.x
(reported by ssivanand@github)
#1978: Using @JsonUnwrapped annotation in builderdeserializer hangs in infinite loop
(reported by roeltje25@github)

2.9.4 (24-Jan-2018)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ private final Object vanillaDeserialize(JsonParser p,
throws IOException
{
Object bean = _valueInstantiator.createUsingDefault(ctxt);
for (; p.getCurrentToken() != JsonToken.END_OBJECT; p.nextToken()) {
for (; p.getCurrentToken() == JsonToken.FIELD_NAME; p.nextToken()) {
String propName = p.getCurrentName();
// Skip field name:
p.nextToken();
Expand Down Expand Up @@ -304,7 +304,7 @@ public Object deserializeFromObject(JsonParser p, DeserializationContext ctxt)
return deserializeWithView(p, ctxt, bean, view);
}
}
for (; p.getCurrentToken() != JsonToken.END_OBJECT; p.nextToken()) {
for (; p.getCurrentToken() == JsonToken.FIELD_NAME; p.nextToken()) {
String propName = p.getCurrentName();
// Skip field name:
p.nextToken();
Expand Down Expand Up @@ -535,8 +535,7 @@ protected Object deserializeWithUnwrapped(JsonParser p, DeserializationContext c
}

final Class<?> activeView = _needViewProcesing ? ctxt.getActiveView() : null;

for (; p.getCurrentToken() != JsonToken.END_OBJECT; p.nextToken()) {
for (; p.getCurrentToken() == JsonToken.FIELD_NAME; p.nextToken()) {
String propName = p.getCurrentName();
p.nextToken();
SettableBeanProperty prop = _beanProperties.find(propName);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package com.fasterxml.jackson.databind.deser.builder;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonUnwrapped;

import com.fasterxml.jackson.databind.*;

import com.fasterxml.jackson.databind.annotation.JsonDeserialize;

public class BuilderInfiniteLoop1978Test extends BaseMapTest
{
static class Builder
{
private SubBean temp;
private int id;

Builder(@JsonProperty("beanId") int beanId) {
this.id = beanId;
}

@JsonUnwrapped(prefix="sub.")
public Builder withThing(SubBean thing) {
this.temp = thing;
return this;
}

public Bean build()
{
Bean bean = new Bean(id);
bean.setThing( temp );
return bean;
}
}

@JsonDeserialize(builder = Builder.class)
static class Bean
{
int id;
SubBean thing;

public Bean(int id) {
this.id = id;
}

public SubBean getThing() {
return thing;
}

public void setThing( SubBean thing ) {
this.thing = thing;
}
}

static class SubBuilder
{
private int element1;
private String element2;

@JsonProperty("el1")
public SubBuilder withElement1(int e1) {
this.element1 = e1;
return this;
}

public SubBean build()
{
SubBean bean = new SubBean();
bean.element1 = element1;
bean.element2 = element2;
return bean;
}
}

@JsonDeserialize(builder = SubBuilder.class)
static class SubBean
{
public int element1;
public String element2;
}

/*
/**********************************************************************
/* Test methods
/**********************************************************************
*/

// for [databind#1978]
public void testInfiniteLoop1978() throws Exception
{
String json = "{\"sub.el1\":34,\"sub.el2\":\"some text\"}";
ObjectMapper mapper = new ObjectMapper();
Bean bean = mapper.readValue( json, Bean.class );
assertNotNull(bean);
}
}

0 comments on commit 277151d

Please sign in to comment.