| 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.databind.*; |
| 8 |
|
| 9 |
import com.fasterxml.jackson.module.jaxb.BaseJaxbTest; |
| 10 |
|
| 11 |
public class TestJaxbFieldAccess extends BaseJaxbTest |
| 12 |
{ |
| 13 |
/* |
| 14 |
/********************************************************** |
| 15 |
/* Helper beans |
| 16 |
/********************************************************** |
| 17 |
*/ |
| 18 |
|
| 19 |
@XmlAccessorType(XmlAccessType.FIELD) |
| 20 |
static class Fields { |
| 21 |
protected int x; |
| 22 |
|
| 23 |
public Fields() { } |
| 24 |
Fields(int x) { this.x = x; } |
| 25 |
} |
| 26 |
|
| 27 |
/* |
| 28 |
/********************************************************** |
| 29 |
/* Unit tests |
| 30 |
/********************************************************** |
| 31 |
*/ |
| 32 |
|
| 33 |
// Verify serialization wrt [JACKSON-202] |
| 34 |
public void testFieldSerialization() throws IOException |
| 35 |
{ |
| 36 |
ObjectMapper mapper = getJaxbMapper(); |
| 37 |
assertEquals("{\"x\":3}", serializeAsString(mapper, new Fields(3))); |
| 38 |
} |
| 39 |
|
| 40 |
// Verify deserialization wrt [JACKSON-202] |
| 41 |
public void testFieldDeserialization() throws IOException |
| 42 |
{ |
| 43 |
ObjectMapper mapper = getJaxbMapper(); |
| 44 |
Fields result = mapper.readValue("{ \"x\":3 }", Fields.class); |
| 45 |
assertEquals(3, result.x); |
| 46 |
} |
| 47 |
} |