|
2 | 2 |
|
3 | 3 | import com.amazon.ion.IonSystem;
|
4 | 4 | import com.amazon.ion.IonValue;
|
| 5 | +import com.amazon.ion.IonStruct; |
5 | 6 | import com.amazon.ion.system.IonSystemBuilder;
|
6 | 7 | import com.fasterxml.jackson.annotation.JsonAnyGetter;
|
7 | 8 | import com.fasterxml.jackson.annotation.JsonAnySetter;
|
| 9 | +import com.fasterxml.jackson.annotation.JsonProperty; |
8 | 10 | import com.fasterxml.jackson.databind.util.AccessPattern;
|
| 11 | +import com.fasterxml.jackson.dataformat.ion.IonObjectMapper; |
9 | 12 | import org.junit.Test;
|
10 | 13 |
|
| 14 | +import java.io.IOException; |
11 | 15 | import java.util.HashMap;
|
12 | 16 | import java.util.Map;
|
13 | 17 | import java.util.Objects;
|
@@ -166,6 +170,39 @@ public void shouldBeAbleToSerializeAndDeserializeStringData() throws Exception {
|
166 | 170 | assertEquals(source, result);
|
167 | 171 | }
|
168 | 172 |
|
| 173 | + static class MyBean { |
| 174 | + public IonStruct required; |
| 175 | + public IonStruct optional; |
| 176 | + |
| 177 | + MyBean( |
| 178 | + @JsonProperty("required") IonStruct required, |
| 179 | + @JsonProperty("optional") IonStruct optional |
| 180 | + ) { |
| 181 | + this.required = required; |
| 182 | + this.optional = optional; |
| 183 | + } |
| 184 | + } |
| 185 | + |
| 186 | + @Test |
| 187 | + public void testWithMissingProperty() throws IOException |
| 188 | + { |
| 189 | + IonSystem ionSystem = IonSystemBuilder.standard().build(); |
| 190 | + IonObjectMapper ionObjectMapper = IonObjectMapper.builder(ionSystem) |
| 191 | + .addModule(new IonValueModule()) |
| 192 | + .build(); |
| 193 | + |
| 194 | + String input1 = "{required:{}, optional:{}}"; |
| 195 | + MyBean deserializedBean1 = ionObjectMapper.readValue(input1, MyBean.class); |
| 196 | + assertEquals(ionSystem.newEmptyStruct(), deserializedBean1.required); |
| 197 | + assertEquals(ionSystem.newEmptyStruct(), deserializedBean1.optional); |
| 198 | + |
| 199 | + // This deserialization should not fail with missing property |
| 200 | + String input2 = "{required:{}}"; |
| 201 | + MyBean deserializedBean2 = ionObjectMapper.readValue(input2, MyBean.class); |
| 202 | + assertEquals(ionSystem.newEmptyStruct(), deserializedBean2.required); |
| 203 | + assertEquals(null, deserializedBean2.optional); |
| 204 | + } |
| 205 | + |
169 | 206 | @Test
|
170 | 207 | public void shouldOverrideNullAccessPatternToBeDynamic() {
|
171 | 208 | IonValueDeserializer deserializer = new IonValueDeserializer();
|
|
0 commit comments