| 1 |
package com.fasterxml.jackson.module.jaxb.misc; |
| 2 |
|
| 3 |
import java.util.List; |
| 4 |
|
| 5 |
import javax.xml.bind.annotation.XmlElement; |
| 6 |
|
| 7 |
import com.fasterxml.jackson.annotation.JsonInclude; |
| 8 |
import com.fasterxml.jackson.databind.ObjectMapper; |
| 9 |
import com.fasterxml.jackson.module.jaxb.BaseJaxbTest; |
| 10 |
import com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule; |
| 11 |
|
| 12 |
public class TestSerializationInclusion extends BaseJaxbTest |
| 13 |
{ |
| 14 |
static class Data { |
| 15 |
private final List<Object> stuff = new java.util.ArrayList<Object>(); |
| 16 |
|
| 17 |
@XmlElement |
| 18 |
public List<Object> getStuff() { |
| 19 |
return stuff; |
| 20 |
} |
| 21 |
} |
| 22 |
|
| 23 |
public void testIssue39() throws Exception |
| 24 |
{ |
| 25 |
// First: use plain JAXB introspector: |
| 26 |
_testInclusion(getJaxbMapper()); |
| 27 |
// and then combination ones |
| 28 |
_testInclusion(getJaxbAndJacksonMapper()); |
| 29 |
_testInclusion(getJacksonAndJaxbMapper()); |
| 30 |
|
| 31 |
// finally: verify using actual module |
| 32 |
ObjectMapper mapper = new ObjectMapper(); |
| 33 |
mapper.registerModule(new JaxbAnnotationModule()); |
| 34 |
_testInclusion(mapper); |
| 35 |
} |
| 36 |
|
| 37 |
private void _testInclusion(ObjectMapper mapper) throws Exception |
| 38 |
{ |
| 39 |
mapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY); |
| 40 |
String json = mapper.writeValueAsString(new Data()); |
| 41 |
assertEquals("{}", json); |
| 42 |
} |
| 43 |
} |