Skip to content

Commit

Permalink
Add failing test for #2016
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed May 2, 2018
1 parent eafac26 commit 90337ec
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 14 deletions.
Expand Up @@ -100,22 +100,22 @@ public String findImplicitPropertyName(AnnotatedMember param) {
}

// [databind#1853]
public static class Product {
public static class Product1853 {
String name;

public Object other, errors;

@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
public Product(@JsonProperty("name") String name) {
public Product1853(@JsonProperty("name") String name) {
this.name = "PROP:" + name;
}

@JsonCreator(mode = JsonCreator.Mode.DELEGATING)
public static Product from(String name){
return new Product(false, "DELEG:"+name);
public static Product1853 from(String name){
return new Product1853(false, "DELEG:"+name);
}

private Product(boolean bogus, String name) {
private Product1853(boolean bogus, String name) {
this.name = name;
}

Expand Down Expand Up @@ -193,17 +193,17 @@ public void testMultiCtor421() throws Exception
// [databind#1853]
public void testSerialization() throws Exception {
assertEquals(quote("testProduct"),
MAPPER.writeValueAsString(new Product(false, "testProduct")));
MAPPER.writeValueAsString(new Product1853(false, "testProduct")));
}

public void testDeserializationFromObject() throws Exception {
final String EXAMPLE_DATA = "{\"name\":\"dummy\",\"other\":{},\"errors\":{}}";
assertEquals("PROP:dummy", MAPPER.readValue(EXAMPLE_DATA, Product.class).getName());
assertEquals("PROP:dummy", MAPPER.readValue(EXAMPLE_DATA, Product1853.class).getName());
}

public void testDeserializationFromString() throws Exception {
assertEquals("DELEG:testProduct",
MAPPER.readValue(quote("testProduct"), Product.class).getName());
MAPPER.readValue(quote("testProduct"), Product1853.class).getName());
}
}

@@ -1,15 +1,15 @@
package com.fasterxml.jackson.databind.deser.creators;

import com.fasterxml.jackson.annotation.JsonCreator;

import java.util.Map;
import java.util.*;

import com.fasterxml.jackson.annotation.JacksonInject;
import com.fasterxml.jackson.annotation.JsonCreator;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;

import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.util.TokenBuffer;

public class TestCreatorsDelegating extends BaseMapTest
Expand Down Expand Up @@ -82,14 +82,28 @@ public MapBean(Map<String, Long> map) {
this.map = map;
}
}


// [databind#2016]
static class Wrapper2016 {
private final List<String> value;

@JsonCreator //(mode = JsonCreator.Mode.DELEGATING)
public Wrapper2016(@JsonDeserialize(as = LinkedList.class) List<String> value) {
this.value = value;
}

public List<String> getValue() {
return value;
}
}

/*
/**********************************************************
/* Unit tests
/* Test methods
/**********************************************************
*/

private final ObjectMapper MAPPER = new ObjectMapper();
private final ObjectMapper MAPPER = newObjectMapper();

public void testBooleanDelegate() throws Exception
{
Expand Down Expand Up @@ -180,4 +194,13 @@ public void testIssue465() throws Exception
bean = MAPPER.readValue(EMPTY_JSON, MapBean.class);
assertEquals(0, bean.map.size());
}

// [databind#2016]
public void testCreatorWithDeserializeAs2016() throws Exception
{
String json = "[\"Hello, World!\"]";
Wrapper2016 actual = MAPPER.readValue(json, Wrapper2016.class);
assertEquals(Collections.singletonList("Hello, World!"), actual.getValue());
assertEquals(LinkedList.class, actual.getValue().getClass());
}
}

0 comments on commit 90337ec

Please sign in to comment.