|
12 | 12 |
|
13 | 13 | package org.eclipse.yasson.defaultmapping.jsonp; |
14 | 14 |
|
15 | | -import org.junit.jupiter.api.*; |
16 | | - |
17 | | -import static org.hamcrest.CoreMatchers.is; |
18 | | -import static org.hamcrest.CoreMatchers.nullValue; |
19 | | -import static org.hamcrest.MatcherAssert.assertThat; |
20 | | -import static org.junit.jupiter.api.Assertions.*; |
21 | | -import static org.eclipse.yasson.Jsonbs.*; |
22 | | - |
23 | | -import org.eclipse.yasson.defaultmapping.jsonp.model.JsonpPojo; |
| 15 | +import java.math.BigDecimal; |
24 | 16 |
|
25 | | -import jakarta.json.*; |
| 17 | +import jakarta.json.Json; |
| 18 | +import jakarta.json.JsonArray; |
| 19 | +import jakarta.json.JsonArrayBuilder; |
| 20 | +import jakarta.json.JsonBuilderFactory; |
| 21 | +import jakarta.json.JsonObject; |
| 22 | +import jakarta.json.JsonObjectBuilder; |
| 23 | +import jakarta.json.JsonString; |
| 24 | +import jakarta.json.JsonValue; |
26 | 25 | import jakarta.json.bind.Jsonb; |
27 | 26 | import jakarta.json.bind.JsonbBuilder; |
28 | 27 | import jakarta.json.bind.JsonbConfig; |
29 | 28 | import jakarta.json.spi.JsonProvider; |
30 | | -import java.math.BigDecimal; |
| 29 | +import org.eclipse.yasson.defaultmapping.jsonp.model.JsonpPojo; |
| 30 | +import org.junit.jupiter.api.Test; |
| 31 | + |
| 32 | +import static org.eclipse.yasson.Jsonbs.defaultJsonb; |
| 33 | +import static org.hamcrest.CoreMatchers.is; |
| 34 | +import static org.hamcrest.CoreMatchers.nullValue; |
| 35 | +import static org.hamcrest.MatcherAssert.assertThat; |
| 36 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 37 | +import static org.junit.jupiter.api.Assertions.assertTrue; |
31 | 38 |
|
32 | 39 | /** |
33 | 40 | * Default mapping JSONP integration tests. |
@@ -254,4 +261,22 @@ public void testJsonNullValue() { |
254 | 261 | deserialized = defaultJsonb.fromJson("{\"jsonValue\":null}", JsonValueWrapper.class); |
255 | 262 | assertThat(deserialized.jsonValue, is(JsonValue.NULL)); |
256 | 263 | } |
| 264 | + |
| 265 | + @Test |
| 266 | + public void testJsonpNullValues() { |
| 267 | + JsonpPojo pojo = new JsonpPojo(); |
| 268 | + String expected = "{}"; |
| 269 | + String nullValues = "{\"jsonObject\":null, \"jsonArray\":null, \"jsonNumber\":null, \"jsonString\":null, " |
| 270 | + + "\"jsonValue\":null }"; |
| 271 | + String json = defaultJsonb.toJson(pojo); |
| 272 | + assertThat(json, is(expected)); |
| 273 | + JsonpPojo deserialized = defaultJsonb.fromJson(expected, JsonpPojo.class); |
| 274 | + assertThat(deserialized.jsonObject, nullValue()); |
| 275 | + deserialized = defaultJsonb.fromJson(nullValues, JsonpPojo.class); |
| 276 | + assertThat(deserialized.jsonObject, nullValue()); |
| 277 | + assertThat(deserialized.jsonArray, nullValue()); |
| 278 | + assertThat(deserialized.jsonNumber, nullValue()); |
| 279 | + assertThat(deserialized.jsonString, nullValue()); |
| 280 | + assertThat(deserialized.jsonValue, is(JsonValue.NULL)); |
| 281 | + } |
257 | 282 | } |
0 commit comments