Debian Codegraph @

src/test/java/com/fasterxml/jackson/module/jaxb/introspect/TestXmlValue.java

raw
1 package com.fasterxml.jackson.module.jaxb.introspect;
2
3 import java.io.IOException;
4
5 import javax.xml.bind.annotation.*;
6
7 import com.fasterxml.jackson.annotation.JsonProperty;
8 import com.fasterxml.jackson.databind.*;
9 import com.fasterxml.jackson.module.jaxb.BaseJaxbTest;
10
11 public class TestXmlValue extends BaseJaxbTest
12 {
13 static class WithXmlValueNoOverride
14 {
15 @XmlValue
16 public int getFoobar() {
17 return 13;
18 }
19 }
20
21 static class WithXmlValueAndOverride
22 {
23 @XmlValue
24 @JsonProperty("number")
25 public int getFoobar() {
26 return 13;
27 }
28 }
29
30 // [Issue#31]
31 static class Query {
32 @XmlValue
33 protected String query;
34
35 public String getQuery() {
36 return query;
37 }
38
39 public void setQuery(final String pQuery) {
40 query = pQuery;
41 }
42 }
43
44 /*
45 /**********************************************************
46 /* Unit tests
47 /**********************************************************
48 */
49
50 // For [Issue#30]
51 public void testXmlValueDefault() throws IOException
52 {
53 ObjectMapper mapper = getJaxbAndJacksonMapper();
54 // default is 'value'
55 assertEquals("{\"value\":13}", mapper.writeValueAsString(new WithXmlValueNoOverride()));
56 }
57
58 // For [Issue#30]
59 public void testXmlValueOverride() throws IOException
60 {
61 ObjectMapper mapper = getJaxbAndJacksonMapper();
62 // default is 'value'
63 assertEquals("{\"number\":13}", mapper.writeValueAsString(new WithXmlValueAndOverride()));
64 }
65
66 // For [Issue#31]
67 public void testXmlValueDefault2() throws IOException
68 {
69 ObjectMapper mapper = getJaxbAndJacksonMapper();
70
71 Query q2 = new Query();
72 q2.query = "foo";
73
74 // default is 'value'
75 Query q = mapper.readValue("{\"value\":\"some stuff\"}", Query.class);
76 assertEquals("some stuff", q.getQuery());
77 }
78 }