Skip to content

Commit

Permalink
feat: Add test cases of bug FasterXML#19
Browse files Browse the repository at this point in the history
  • Loading branch information
xdrsynapse committed Mar 6, 2022
1 parent 86ca36c commit e69a17a
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;

import java.beans.ConstructorProperties;

public class JsonValueDeserializationTest extends TestBase
{
private final ObjectMapper MAPPER = newMapper();
Expand Down Expand Up @@ -109,4 +111,24 @@ public void testNullNode() throws Exception
final JsonValue deserializedNull = MAPPER.readValue(serializedNull, JsonValue.class);
assertEquals(JsonValue.NULL, deserializedNull);
}

// for [datatype-jsr353#19]
public void testConstructorProperties() throws Exception
{
final String JSON = "{\"obj1\":{}}";
ObjectImpl ob = MAPPER.readValue(JSON, ObjectImpl.class);
assertTrue(ob.obj1 instanceof JsonObject);
assertNull(ob.obj2);
}

static class ObjectImpl {
JsonValue obj1;
JsonValue obj2;

@ConstructorProperties({"obj1", "obj2"})
public ObjectImpl(JsonValue obj1, JsonValue obj2) {
this.obj1 = obj1;
this.obj2 = obj2;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;

import java.beans.ConstructorProperties;

public class JsonValueDeserializationTest extends TestBase
{
private final ObjectMapper MAPPER = newMapper();
Expand Down Expand Up @@ -109,4 +111,24 @@ public void testNullNode() throws Exception
final JsonValue deserializedNull = MAPPER.readValue(serializedNull, JsonValue.class);
assertEquals(JsonValue.NULL, deserializedNull);
}

// for [datatype-jsr353#19]
public void testConstructorProperties() throws Exception
{
final String JSON = "{\"obj1\":{}}";
ObjectImpl ob = MAPPER.readValue(JSON, ObjectImpl.class);
assertTrue(ob.obj1 instanceof JsonObject);
assertNull(ob.obj2);
}

static class ObjectImpl {
JsonValue obj1;
JsonValue obj2;

@ConstructorProperties({"obj1", "obj2"})
public ObjectImpl(JsonValue obj1, JsonValue obj2) {
this.obj1 = obj1;
this.obj2 = obj2;
}
}
}

0 comments on commit e69a17a

Please sign in to comment.