Skip to content

Commit bb18040

Browse files
committed
One more test fix
1 parent 2207de8 commit bb18040

File tree

3 files changed

+40
-5
lines changed

3 files changed

+40
-5
lines changed

hibernate4/src/test/java/tools/jackson/datatype/hibernate4/LazyLoadingTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,11 @@ public void testSerializeIdentifierFeature() throws JacksonException {
7171
EntityManager em = emf.createEntityManager();
7272
Customer customerRef = em.getReference(Customer.class, 103);
7373
em.close();
74-
assertFalse(Hibernate.isInitialized(customerRef));
74+
assertFalse(Hibernate.isInitialized(customerRef));
7575

76-
String json = objectMapper.writeValueAsString(customerRef);
77-
assertFalse(Hibernate.isInitialized(customerRef));
78-
assertEquals("{\"customerNumber\":103}", json);
76+
String json = objectMapper.writeValueAsString(customerRef);
77+
assertFalse(Hibernate.isInitialized(customerRef));
78+
assertEquals("{\"customerNumber\":103}", json);
7979
} finally {
8080
emf.close();
8181
}

hibernate4/src/test/java/tools/jackson/datatype/hibernate4/TransientTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
88
import com.fasterxml.jackson.annotation.JsonView;
99

10+
import tools.jackson.databind.MapperFeature;
1011
import tools.jackson.databind.ObjectMapper;
1112
import tools.jackson.databind.json.JsonMapper;
1213

@@ -64,7 +65,9 @@ public void testSimpleTransient() throws Exception
6465
@Test
6566
public void testTransientWithView() throws Exception
6667
{
67-
ObjectMapper mapper = mapperWithModule(false);
68+
ObjectMapper mapper = mapperBuilderWithModule(false)
69+
.enable(MapperFeature.DEFAULT_VIEW_INCLUSION)
70+
.build();
6871
assertEquals(aposToQuotes("{'aaa':'xxx'}"),
6972
mapper.writerWithView(PublicView.class)
7073
.writeValueAsString(new WithTransientAndView()));

hibernate5/src/test/java/tools/jackson/datatype/hibernate5/TransientTest.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
import org.junit.jupiter.api.Test;
66

77
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
8+
import com.fasterxml.jackson.annotation.JsonView;
9+
10+
import tools.jackson.databind.MapperFeature;
811
import tools.jackson.databind.ObjectMapper;
912
import tools.jackson.databind.json.JsonMapper;
1013

@@ -23,6 +26,21 @@ static class WithTransient {
2326
public int b = 2;
2427
}
2528

29+
public static interface PublicView {}
30+
public static interface PrivateView {}
31+
32+
@JsonPropertyOrder({"aaa", "bbb", "ccc", "ddd"})
33+
static class WithTransientAndView {
34+
public String aaa = "xxx";
35+
@Transient
36+
public String bbb = "xxx";
37+
@Transient
38+
@JsonView(PublicView.class)
39+
public String ccc = "xxx";
40+
@JsonView(PrivateView.class)
41+
public String ddd = "xxx";
42+
}
43+
2644
/*
2745
/**********************************************************************
2846
/* Test methods
@@ -43,4 +61,18 @@ public void testSimpleTransient() throws Exception
4361

4462
assertEquals(aposToQuotes("{'a':1,'b':2}"), mapper.writeValueAsString(new WithTransient()));
4563
}
64+
65+
@Test
66+
public void testTransientWithView() throws Exception
67+
{
68+
ObjectMapper mapper = mapperBuilderWithModule(false)
69+
.enable(MapperFeature.DEFAULT_VIEW_INCLUSION)
70+
.build();
71+
assertEquals(aposToQuotes("{'aaa':'xxx'}"),
72+
mapper.writerWithView(PublicView.class)
73+
.writeValueAsString(new WithTransientAndView()));
74+
assertEquals(aposToQuotes("{'aaa':'xxx','ddd':'xxx'}"),
75+
mapper.writerWithView(PrivateView.class)
76+
.writeValueAsString(new WithTransientAndView()));
77+
}
4678
}

0 commit comments

Comments
 (0)