|
| 1 | +package com.fasterxml.jackson.databind.introspect; |
| 2 | + |
| 3 | +import com.fasterxml.jackson.annotation.JsonIgnore; |
| 4 | +import com.fasterxml.jackson.annotation.JsonProperty; |
| 5 | +import com.fasterxml.jackson.annotation.JsonPropertyOrder; |
| 6 | +import com.fasterxml.jackson.databind.BaseMapTest; |
| 7 | +import com.fasterxml.jackson.databind.MapperFeature; |
| 8 | +import com.fasterxml.jackson.databind.ObjectMapper; |
| 9 | +import java.io.Serializable; |
| 10 | + |
| 11 | +public class Transient3948Test extends BaseMapTest { |
| 12 | + |
| 13 | + @JsonPropertyOrder(alphabetic = true) |
| 14 | + static class Obj implements Serializable { |
| 15 | + |
| 16 | + private static final long serialVersionUID = -1L; |
| 17 | + |
| 18 | + private String a = "hello"; |
| 19 | + |
| 20 | + @JsonIgnore |
| 21 | + private transient String b = "world"; |
| 22 | + |
| 23 | + @JsonProperty("cat") |
| 24 | + private String c = "jackson"; |
| 25 | + |
| 26 | + @JsonProperty("dog") |
| 27 | + private transient String d = "databind"; |
| 28 | + |
| 29 | + public String getA() { |
| 30 | + return a; |
| 31 | + } |
| 32 | + |
| 33 | + public String getB() { |
| 34 | + return b; |
| 35 | + } |
| 36 | + |
| 37 | + public String getC() { |
| 38 | + return c; |
| 39 | + } |
| 40 | + |
| 41 | + public String getD() { |
| 42 | + return d; |
| 43 | + } |
| 44 | + } |
| 45 | + |
| 46 | + final ObjectMapper DEFAULT_MAPPER = newJsonMapper(); |
| 47 | + |
| 48 | + final ObjectMapper MAPPER_TRANSIENT = jsonMapperBuilder() |
| 49 | + .configure(MapperFeature.PROPAGATE_TRANSIENT_MARKER, true) |
| 50 | + .build(); |
| 51 | + |
| 52 | + public void testJsonIgnoreSerialization() throws Exception { |
| 53 | + Obj obj1 = new Obj(); |
| 54 | + |
| 55 | + String json = DEFAULT_MAPPER.writeValueAsString(obj1); |
| 56 | + |
| 57 | + assertEquals(a2q("{'a':'hello','b':'world','cat':'jackson','dog':'databind'}"), json); |
| 58 | + } |
| 59 | + |
| 60 | + public void testJsonIgnoreSerializationTransient() throws Exception { |
| 61 | + Obj obj1 = new Obj(); |
| 62 | + |
| 63 | + String json = MAPPER_TRANSIENT.writeValueAsString(obj1); |
| 64 | + |
| 65 | + assertEquals(a2q("{'a':'hello','cat':'jackson','dog':'databind'}"), json); |
| 66 | + } |
| 67 | +} |
0 commit comments