Skip to content

Commit

Permalink
Add failing test for #123
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Jan 1, 2021
1 parent 40bc785 commit 3146384
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 34 deletions.
Expand Up @@ -4,10 +4,12 @@

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

import com.fasterxml.jackson.databind.ObjectMapper;

import com.fasterxml.jackson.module.afterburner.AfterburnerTestBase;

public class TestSimpleDeserialize extends AfterburnerTestBase
public class BasicDeserializeTest extends AfterburnerTestBase
{
public enum MyEnum {
A, B, C;
Expand Down Expand Up @@ -143,6 +145,23 @@ static class Issue60Pojo {
public List<Object> foos;
}

// [modules-base#123]: fluent method(s)
public static class Model123 {
int value = 10;

protected Model123() { }
public Model123(int v) { value = v; }

public int getValue() {
return value;
}

public Model123 setValue(int value) {
this.value = value;
return this;
}
}

/*
/**********************************************************************
/* Test methods, method access
Expand Down Expand Up @@ -325,38 +344,13 @@ public void testProblemWithIndentation() throws Exception {
assertEquals(0, pojo.foos.size());
}

// 28-Sep-2019, tatu: I do not fully understand what this method tried to do;
// it seemed to be a contribution from July 2016. But I noticed that it breaks
// with JDK 12 and unlikely to be allowed so let's comment it out.
/*
// [modules-base#123]
public void testFluentMethod() throws Exception
{
String json = MAPPER.writeValueAsString(new Model123(28));

static class CheckGeneratedDeserializerName {
public String stringField;
}
@SuppressWarnings("unchecked")
public void testGeneratedDeserializerName() throws Exception {
MAPPER.readValue("{\"stringField\":\"foo\"}", CheckGeneratedDeserializerName.class);
ClassLoader cl = getClass().getClassLoader();
Field declaredField = ClassLoader.class.getDeclaredField("classes");
declaredField.setAccessible(true);
// 06-Sep-2017, tatu: Hmmh. Whatever this code does... is not very robust.
// But has to do for now. OpenJDK 7 had issues with size, increased:
Class<?>[] os = new Class[8192];
((Vector<Class<?>>) declaredField.get(cl)).copyInto(os);
String expectedClassName = TestSimpleDeserialize.class.getCanonicalName()
+ "$CheckGeneratedDeserializerName$Access4JacksonDeserializer";
for (Class<?> clz : os) {
if (clz == null) {
break;
}
if (clz.getCanonicalName() != null
&& clz.getCanonicalName().startsWith(expectedClassName)) {
return;
}
}
fail("Expected class not found:" + expectedClassName);
Model123 result = MAPPER.readValue(json, Model123.class);
assertNotNull(result);
assertEquals(28, result.value);
}
*/
}
@@ -1,12 +1,15 @@
package com.fasterxml.jackson.module.blackbird.deser;

import java.util.List;

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

import com.fasterxml.jackson.databind.ObjectMapper;

import com.fasterxml.jackson.module.blackbird.BlackbirdTestBase;

public class TestSimpleDeserialize extends BlackbirdTestBase
public class BasicDeserializeTest extends BlackbirdTestBase
{
public enum MyEnum {
A, B, C;
Expand Down
@@ -0,0 +1,38 @@
package com.fasterxml.jackson.module.blackbird.failing;

import com.fasterxml.jackson.databind.ObjectMapper;

import com.fasterxml.jackson.module.blackbird.BlackbirdTestBase;

// Failing test from "BasicDeserializeTest", see [modules-base#123]
public class BasicDeserialize123Test extends BlackbirdTestBase
{
// [modules-base#123]: fluent method(s)
static class Model123 {
int value = 10;

protected Model123() { }
public Model123(int v) { value = v; }

public int getValue() {
return value;
}

public Model123 setValue(int value) {
this.value = value;
return this;
}
}

private final ObjectMapper MAPPER = newObjectMapper();

// [modules-base#123]
public void testFluentMethod() throws Exception
{
String json = MAPPER.writeValueAsString(new Model123(28));

Model123 result = MAPPER.readValue(json, Model123.class);
assertNotNull(result);
assertEquals(28, result.value);
}
}

0 comments on commit 3146384

Please sign in to comment.