-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathJsonIgnoreAnnotationTest.java
46 lines (35 loc) · 1.25 KB
/
JsonIgnoreAnnotationTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package com.annotation.jackson;
import java.io.IOException;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
@Slf4j
class JsonIgnoreAnnotationTest {
ObjectMapper objectMapper;
@BeforeClass
void setUp() {
objectMapper = new ObjectMapper();
}
@AfterEach
void tearDown() {
}
@Test
public void testSerializingWithJsonIgnore() throws JsonProcessingException {
final String jsonString = objectMapper.writeValueAsString(new JsonIgnoreAnnotation());
log.info(jsonString);
// Assert.assertThat(jsonString, Matchers.containsString("James Clark"));
// Assert.assertThat(jsonString, not(containsString("productId")));
}
@Test
public void testDeSerializingWithJsonIgnore() throws IOException {
final String jsonString = "{\"personId\": 231, \"name\": \"Mary Parker\"}";
final ObjectMapper mapper = new ObjectMapper();
final JsonIgnoreAnnotation bean = objectMapper.readValue(jsonString, JsonIgnoreAnnotation.class);
System.out.println(bean);
// assertThat(bean.name, is(equalTo("Mary Parker")));
// assertThat(bean.personId, is(not(equalTo(231L))));
}
}