Debian Codegraph @

src/test/java/com/fasterxml/jackson/module/jaxb/failing/TestUnwrapping.java

raw
1 package com.fasterxml.jackson.module.jaxb.failing;
2
3 import javax.xml.bind.annotation.*;
4
5 import com.fasterxml.jackson.annotation.JsonUnwrapped;
6 import com.fasterxml.jackson.databind.*;
7 import com.fasterxml.jackson.databind.introspect.AnnotationIntrospectorPair;
8 import com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector;
9 import com.fasterxml.jackson.module.jaxb.BaseJaxbTest;
10 import com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector;
11
12 public class TestUnwrapping extends BaseJaxbTest
13 {
14 @XmlRootElement
15 static class Bean<R>
16 {
17 @JsonUnwrapped
18 @XmlAnyElement(lax = true)
19 @XmlElementRefs( { @XmlElementRef(name = "a", type = A.class),
20 @XmlElementRef(name = "b", type = B.class) })
21 public R r;
22 public String name;
23
24 public Bean() { }
25 }
26
27 static class A {
28 public int count;
29
30 public A() { }
31
32 public A(int count) {
33 this.count = count;
34 }
35 }
36
37 static class B {
38 public String type;
39
40 public B() { }
41
42 public B(String type) {
43 this.type = type;
44 }
45 }
46
47 /*
48 /**********************************************************
49 /* Unit tests
50 /**********************************************************
51 */
52
53 // not asserting anything
54 public void testXmlElementAndXmlElementRefs() throws Exception
55 {
56 Bean<A> bean = new Bean<A>();
57 bean.r = new A(12);
58 bean.name = "test";
59 ObjectMapper mapper = new ObjectMapper();
60 AnnotationIntrospector pair = new AnnotationIntrospectorPair(
61 new JacksonAnnotationIntrospector(),
62 new JaxbAnnotationIntrospector(mapper.getTypeFactory())
63 );
64 mapper.setAnnotationIntrospector(pair);
65
66 // mapper.setAnnotationIntrospector(new JacksonAnnotationIntrospector());
67 // mapper.setAnnotationIntrospector(new JaxbAnnotationIntrospector());
68
69 String json = mapper.writeValueAsString(bean);
70 // !!! TODO: verify
71 assertNotNull(json);
72 }
73 }