Skip to content

Commit a07e795

Browse files
patveckcowtowncoder
authored andcommitted
Add tests for Jakarta
1 parent fe4ef2b commit a07e795

File tree

1 file changed

+42
-1
lines changed

1 file changed

+42
-1
lines changed

jakarta-jsonp/src/test/java/com/fasterxml/jackson/datatype/jsonp/JsonMergePatchDeserializationTest.java

+42-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.fasterxml.jackson.databind.ObjectMapper;
44

5+
import jakarta.json.JsonArray;
56
import jakarta.json.JsonMergePatch;
67
import jakarta.json.JsonObject;
78
import jakarta.json.JsonString;
@@ -16,7 +17,7 @@ public class JsonMergePatchDeserializationTest extends TestBase {
1617

1718
private static final ObjectMapper MAPPER = newMapper();
1819

19-
public void testDeserializationAndPatching() throws Exception {
20+
public void testObjectDeserializationAndPatching() throws Exception {
2021
final String json = "{" +
2122
"\"name\":\"Json\"" +
2223
"}";
@@ -39,6 +40,46 @@ public void testDeserializationAndPatching() throws Exception {
3940
assertThat(patchedPerson, is(new Person("Json", "Smith")));
4041
}
4142

43+
public void testArrayDeserializationAndPatching() throws Exception {
44+
final String json = "[" +
45+
"\"name\",\"Json\"" +
46+
"]";
47+
48+
final JsonMergePatch jsonMergePatch = MAPPER.readValue(json, JsonMergePatch.class);
49+
final JsonValue jsonPatchAsJsonValue = jsonMergePatch.toJsonValue();
50+
assertThat(jsonPatchAsJsonValue, instanceOf(JsonArray.class));
51+
52+
final JsonArray jsonPatchAsJsonArray = jsonPatchAsJsonValue.asJsonArray();
53+
assertThat(jsonPatchAsJsonArray.size(), is(2));
54+
assertThat(jsonPatchAsJsonArray.get(0), instanceOf(JsonString.class));
55+
assertThat(((JsonString)jsonPatchAsJsonArray.get(0)).getString(), is("name"));
56+
assertThat(jsonPatchAsJsonArray.get(1), instanceOf(JsonString.class));
57+
assertThat(((JsonString)jsonPatchAsJsonArray.get(1)).getString(), is("Json"));
58+
59+
assertThat(serializeAsString(jsonPatchAsJsonValue), is(json));
60+
61+
final Person person = new Person("John", "Smith");
62+
final JsonValue personJson = MAPPER.convertValue(person, JsonValue.class);
63+
final JsonValue patchedPersonJson = jsonMergePatch.apply(personJson);
64+
assertThat(patchedPersonJson, instanceOf(JsonArray.class));
65+
}
66+
67+
public void testScalarDeserializationAndPatching() throws Exception {
68+
final String json = "\"name\"";
69+
70+
final JsonMergePatch jsonMergePatch = MAPPER.readValue(json, JsonMergePatch.class);
71+
final JsonValue jsonPatchAsJsonValue = jsonMergePatch.toJsonValue();
72+
assertThat(jsonPatchAsJsonValue, instanceOf(JsonString.class));
73+
74+
assertThat(serializeAsString(jsonPatchAsJsonValue), is(json));
75+
76+
final Person person = new Person("John", "Smith");
77+
final JsonValue personJson = MAPPER.convertValue(person, JsonValue.class);
78+
final JsonValue patchedPersonJson = jsonMergePatch.apply(personJson);
79+
assertThat(patchedPersonJson, instanceOf(JsonString.class));
80+
assertThat(((JsonString)patchedPersonJson).getString(), is("name"));
81+
}
82+
4283
static class Person {
4384
private String name;
4485
private String lastName;

0 commit comments

Comments
 (0)