|
37 | 37 | import com.baeldung.jackson.dtos.MyMixInForIgnoreType; |
38 | 38 | import com.baeldung.jackson.dtos.withEnum.DistanceEnumWithValue; |
39 | 39 | import com.baeldung.jackson.exception.UserWithRoot; |
| 40 | +import com.baeldung.jackson.exception.UserWithRootNamespace; |
40 | 41 | import com.baeldung.jackson.jsonview.Item; |
41 | 42 | import com.baeldung.jackson.jsonview.Views; |
42 | 43 | import com.fasterxml.jackson.core.JsonProcessingException; |
|
47 | 48 | import com.fasterxml.jackson.databind.ser.FilterProvider; |
48 | 49 | import com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter; |
49 | 50 | import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider; |
| 51 | +import com.fasterxml.jackson.dataformat.xml.XmlMapper; |
50 | 52 |
|
51 | 53 | public class JacksonAnnotationUnitTest { |
52 | 54 |
|
@@ -378,13 +380,40 @@ public void whenDisablingAllAnnotations_thenAllDisabled() throws JsonProcessingE |
378 | 380 | public void whenDeserializingUsingJsonAlias_thenCorrect() throws IOException { |
379 | 381 |
|
380 | 382 | // arrange |
381 | | - String json = "{\"fName\": \"Alex\", \"lastName\": \"Theedom\"}"; |
| 383 | + String json = "{\"fName\": \"John\", \"lastName\": \"Green\"}"; |
382 | 384 |
|
383 | 385 | // act |
384 | 386 | AliasBean aliasBean = new ObjectMapper().readerFor(AliasBean.class).readValue(json); |
385 | 387 |
|
386 | 388 | // assert |
387 | | - assertThat(aliasBean.getFirstName(), is("Alex")); |
| 389 | + assertThat(aliasBean.getFirstName(), is("John")); |
388 | 390 | } |
| 391 | + |
| 392 | + @Test |
| 393 | + public void whenSerializingUsingXMLRootNameWithNameSpace_thenCorrect() throws JsonProcessingException { |
| 394 | + |
| 395 | + // arrange |
| 396 | + UserWithRootNamespace author = new UserWithRootNamespace(1, "John"); |
| 397 | + |
| 398 | + // act |
| 399 | + ObjectMapper mapper = new XmlMapper(); |
| 400 | + mapper = mapper.enable(SerializationFeature.WRAP_ROOT_VALUE).enable(SerializationFeature.INDENT_OUTPUT); |
| 401 | + String result = mapper.writeValueAsString(author); |
| 402 | + |
| 403 | + // assert |
| 404 | + assertThat(result, containsString("<user xmlns=\"users\">")); |
| 405 | + |
| 406 | + /* |
| 407 | + <user xmlns="users"> |
| 408 | + <id xmlns="">3006b44a-cf62-4cfe-b3d8-30dc6c46ea96</id> |
| 409 | + <id xmlns="">1</id> |
| 410 | + <name xmlns="">John</name> |
| 411 | + <items xmlns=""/> |
| 412 | + </user> |
| 413 | + */ |
| 414 | + |
| 415 | + } |
| 416 | + |
| 417 | + |
389 | 418 |
|
390 | 419 | } |
0 commit comments