Skip to content

Commit

Permalink
Add failing test for #1868, related
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Jan 11, 2018
1 parent 615bf02 commit b744bf3
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ public ValueInstantiator findValueInstantiator(DeserializationContext ctxt,
}
}

// Sanity check: does the chosen instantatior have incomplete creators?
// Sanity check: does the chosen ValueInstantiator have incomplete creators?
if (instantiator.getIncompleteParameter() != null) {
final AnnotatedParameter nonAnnotatedParam = instantiator.getIncompleteParameter();
final AnnotatedWithParams ctor = nonAnnotatedParam.getOwner();
Expand All @@ -281,7 +281,8 @@ private ValueInstantiator _findStdValueInstantiator(DeserializationConfig config
BeanDescription beanDesc)
throws JsonMappingException
{
if (beanDesc.getBeanClass() == JsonLocation.class) {
Class<?> raw = beanDesc.getBeanClass();
if (raw == JsonLocation.class) {
return new JsonLocationInstantiator();
}
return null;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package com.fasterxml.jackson.failing;

import java.util.*;

import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.databind.BaseMapTest;
import com.fasterxml.jackson.databind.ObjectMapper;

// Unit tests for [databind#1868], related
public class TestDefaultForUtilCollections1868 extends BaseMapTest
{
private final ObjectMapper DEFAULT_MAPPER = new ObjectMapper();
{
DEFAULT_MAPPER.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.PROPERTY);
}

/*
/**********************************************************
/* Unit tests, "empty" types
/**********************************************************
*/

public void testEmptyList() throws Exception {
_verifyCollection(Collections.emptyList());
}

public void testEmptySet() throws Exception {
_verifyCollection(Collections.emptySet());
}

public void testEmptyMap() throws Exception {
_verifyMap(Collections.emptyMap());
}

/*
/**********************************************************
/* Unit tests, "singleton" types
/**********************************************************
*/

public void testSingletonList() throws Exception {
_verifyCollection(Collections.singletonList(Arrays.asList("TheOne")));
}

public void testSingletonSet() throws Exception {
_verifyCollection(Collections.singleton(Arrays.asList("TheOne")));
}

public void testSingletonMap() throws Exception {
_verifyMap(Collections.singletonMap("foo", "bar"));
}

/*
/**********************************************************
/* Unit tests, "unmodifiable" types
/**********************************************************
*/

public void testUnmodifiableList() throws Exception {
_verifyCollection(Collections.unmodifiableList(Arrays.asList("first", "second")));
}

public void testUnmodifiableSet() throws Exception
{
Set<String> input = new LinkedHashSet<>(Arrays.asList("first", "second"));
_verifyCollection(Collections.unmodifiableSet(input));
}

public void testUnmodifiableMap() throws Exception
{
Map<String,String> input = new LinkedHashMap<>();
input.put("a", "b");
input.put("c", "d");
_verifyMap(Collections.unmodifiableMap(input));
}

/*
/**********************************************************
/* Helper methods
/**********************************************************
*/

protected void _verifyCollection(Collection<?> exp) throws Exception
{
String json = DEFAULT_MAPPER.writeValueAsString(exp);
Collection<?> act = DEFAULT_MAPPER.readValue(json, Collection.class);

assertEquals(exp, act);
assertEquals(exp.getClass(), act.getClass());
}

protected void _verifyMap(Map<?,?> exp) throws Exception
{
String json = DEFAULT_MAPPER.writeValueAsString(exp);
Map<?,?> act = DEFAULT_MAPPER.readValue(json, Map.class);

assertEquals(exp, act);
assertEquals(exp.getClass(), act.getClass());
}
}

0 comments on commit b744bf3

Please sign in to comment.