Debian Codegraph @

src/test/java/com/fasterxml/jackson/module/jaxb/BaseJaxbTest.java

raw
1 package com.fasterxml.jackson.module.jaxb;
2
3 import java.io.IOException;
4 import java.util.Map;
5
6 import com.fasterxml.jackson.databind.*;
7 import com.fasterxml.jackson.databind.introspect.AnnotationIntrospectorPair;
8 import com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector;
9
10 import com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector;
11
12 public abstract class BaseJaxbTest
13 extends junit.framework.TestCase
14 {
15 protected BaseJaxbTest() { }
16
17 /*
18 /**********************************************************************
19 /* Factory methods
20 /**********************************************************************
21 */
22
23 protected ObjectMapper getJaxbMapper()
24 {
25 ObjectMapper mapper = new ObjectMapper();
26 AnnotationIntrospector intr = new JaxbAnnotationIntrospector(mapper.getTypeFactory());
27 mapper.setAnnotationIntrospector(intr);
28 return mapper;
29 }
30
31 protected ObjectMapper getJaxbAndJacksonMapper()
32 {
33 ObjectMapper mapper = new ObjectMapper();
34 AnnotationIntrospector intr = new AnnotationIntrospectorPair(new JaxbAnnotationIntrospector(
35 mapper.getTypeFactory()), new JacksonAnnotationIntrospector());
36 mapper.setAnnotationIntrospector(intr);
37 return mapper;
38 }
39
40 protected ObjectMapper getJacksonAndJaxbMapper()
41 {
42 ObjectMapper mapper = new ObjectMapper();
43 AnnotationIntrospector intr = new AnnotationIntrospectorPair(new JacksonAnnotationIntrospector(),
44 new JaxbAnnotationIntrospector(mapper.getTypeFactory()) );
45 mapper.setAnnotationIntrospector(intr);
46 return mapper;
47 }
48
49 /*
50 /**********************************************************************
51 /* Helper methods
52 /**********************************************************************
53 */
54
55 @SuppressWarnings("unchecked")
56 protected Map<String,Object> writeAndMap(ObjectMapper m, Object value)
57 throws IOException
58 {
59 String str = m.writeValueAsString(value);
60 return (Map<String,Object>) m.readValue(str, Map.class);
61 }
62
63 protected Map<String,Object> writeAndMap(Object value)
64 throws IOException
65 {
66 return writeAndMap(new ObjectMapper(), value);
67 }
68
69 protected String serializeAsString(ObjectMapper m, Object value)
70 throws IOException
71 {
72 return m.writeValueAsString(value);
73 }
74
75 protected String serializeAsString(Object value)
76 throws IOException
77 {
78 return serializeAsString(new ObjectMapper(), value);
79 }
80 }