Skip to content

Commit af2414a

Browse files
committed
Add a unit test to verify that view + transient works.
1 parent 9c4c35a commit af2414a

File tree

1 file changed

+14
-21
lines changed

1 file changed

+14
-21
lines changed

hibernate4/src/test/java/com/fasterxml/jackson/datatype/hibernate4/TransientTest.java

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,20 @@ static class WithTransient {
2121
}
2222

2323
public static interface PublicView {}
24-
public static interface OtherView {}
24+
public static interface PrivateView {}
2525

26-
@JsonPropertyOrder({"a", "b"})
26+
@JsonPropertyOrder({"aaa", "bbb", "ccc", "ddd"})
2727
static class WithTransientAndView {
28-
public int a = 3;
29-
30-
@JsonView(PublicView.class)
31-
@Transient
32-
public int b = 4;
28+
public String aaa = "xxx";
29+
@Transient
30+
public String bbb = "xxx";
31+
@Transient
32+
@JsonView(PublicView.class)
33+
public String ccc = "xxx";
34+
@JsonView(PrivateView.class)
35+
public String ddd = "xxx";
3336
}
34-
37+
3538
/*
3639
/**********************************************************************
3740
/* Test methods
@@ -55,21 +58,11 @@ public void testSimpleTransient() throws Exception
5558
public void testTransientWithView() throws Exception
5659
{
5760
ObjectMapper mapper = mapperWithModule(false);
58-
assertEquals(aposToQuotes("{'a':3}"),
59-
mapper.writerWithView(PublicView.class)
60-
.writeValueAsString(new WithTransientAndView()));
61-
62-
Hibernate4Module mod = hibernateModule(false);
63-
mod.disable(Hibernate4Module.Feature.USE_TRANSIENT_ANNOTATION);
64-
mapper = new ObjectMapper().registerModule(mod);
65-
66-
assertEquals(aposToQuotes("{'a':3,'b':4}"),
61+
assertEquals(aposToQuotes("{'aaa':'xxx'}"),
6762
mapper.writerWithView(PublicView.class)
6863
.writeValueAsString(new WithTransientAndView()));
69-
70-
// although not if not within view
71-
assertEquals(aposToQuotes("{'a':3}"),
72-
mapper.writerWithView(OtherView.class)
64+
assertEquals(aposToQuotes("{'aaa':'xxx','ddd':'xxx'}"),
65+
mapper.writerWithView(PrivateView.class)
7366
.writeValueAsString(new WithTransientAndView()));
7467
}
7568
}

0 commit comments

Comments
 (0)