11package com .baeldung .jackson .test ;
22
3- import static org .hamcrest .Matchers .containsString ;
4- import static org .hamcrest .Matchers .is ;
5- import static org .hamcrest .Matchers .not ;
6- import static org .junit .Assert .assertEquals ;
7- import static org .junit .Assert .assertThat ;
8-
9- import java .io .IOException ;
10- import java .text .ParseException ;
11- import java .text .SimpleDateFormat ;
12- import java .util .Date ;
13- import java .util .TimeZone ;
14-
15- import org .junit .Test ;
16-
17- import com .baeldung .jackson .annotation .BeanWithCreator ;
18- import com .baeldung .jackson .annotation .BeanWithCustomAnnotation ;
19- import com .baeldung .jackson .annotation .BeanWithFilter ;
20- import com .baeldung .jackson .annotation .BeanWithGetter ;
21- import com .baeldung .jackson .annotation .BeanWithIgnore ;
22- import com .baeldung .jackson .annotation .BeanWithInject ;
23- import com .baeldung .jackson .annotation .ExtendableBean ;
24- import com .baeldung .jackson .annotation .MyBean ;
25- import com .baeldung .jackson .annotation .PrivateBean ;
26- import com .baeldung .jackson .annotation .RawBean ;
27- import com .baeldung .jackson .annotation .UnwrappedUser ;
28- import com .baeldung .jackson .annotation .UserWithIgnoreType ;
29- import com .baeldung .jackson .annotation .Zoo ;
3+ import com .baeldung .jackson .annotation .*;
304import com .baeldung .jackson .bidirection .ItemWithIdentity ;
315import com .baeldung .jackson .bidirection .ItemWithRef ;
326import com .baeldung .jackson .bidirection .UserWithIdentity ;
3812import com .baeldung .jackson .exception .UserWithRoot ;
3913import com .baeldung .jackson .jsonview .Item ;
4014import com .baeldung .jackson .jsonview .Views ;
41- import com .fasterxml .jackson .core .JsonParseException ;
4215import com .fasterxml .jackson .core .JsonProcessingException ;
4316import com .fasterxml .jackson .databind .InjectableValues ;
4417import com .fasterxml .jackson .databind .MapperFeature ;
4720import com .fasterxml .jackson .databind .ser .FilterProvider ;
4821import com .fasterxml .jackson .databind .ser .impl .SimpleBeanPropertyFilter ;
4922import com .fasterxml .jackson .databind .ser .impl .SimpleFilterProvider ;
23+ import org .junit .Test ;
24+
25+ import java .io .IOException ;
26+ import java .text .ParseException ;
27+ import java .text .SimpleDateFormat ;
28+ import java .util .Date ;
29+ import java .util .TimeZone ;
30+
31+ import static org .hamcrest .Matchers .*;
32+ import static org .junit .Assert .assertEquals ;
33+ import static org .junit .Assert .assertThat ;
5034
5135public class JacksonAnnotationTest {
5236
@@ -101,7 +85,7 @@ public void whenSerializingUsingJsonRootName_thenCorrect() throws JsonProcessing
10185 }
10286
10387 @ Test
104- public void whenSerializingUsingJsonValue_thenCorrect () throws JsonParseException , IOException {
88+ public void whenSerializingUsingJsonValue_thenCorrect () throws IOException {
10589 final String enumAsString = new ObjectMapper ().writeValueAsString (TypeEnumWithValue .TYPE1 );
10690
10791 assertThat (enumAsString , is ("\" Type A\" " ));
@@ -122,15 +106,15 @@ public void whenSerializingUsingJsonSerialize_thenCorrect() throws JsonProcessin
122106 // ========================= Deserializing annotations ============================
123107
124108 @ Test
125- public void whenDeserializingUsingJsonCreator_thenCorrect () throws JsonProcessingException , IOException {
109+ public void whenDeserializingUsingJsonCreator_thenCorrect () throws IOException {
126110 final String json = "{\" id\" :1,\" theName\" :\" My bean\" }" ;
127111
128112 final BeanWithCreator bean = new ObjectMapper ().readerFor (BeanWithCreator .class ).readValue (json );
129113 assertEquals ("My bean" , bean .name );
130114 }
131115
132116 @ Test
133- public void whenDeserializingUsingJsonInject_thenCorrect () throws JsonProcessingException , IOException {
117+ public void whenDeserializingUsingJsonInject_thenCorrect () throws IOException {
134118 final String json = "{\" name\" :\" My bean\" }" ;
135119 final InjectableValues inject = new InjectableValues .Std ().addValue (int .class , 1 );
136120
@@ -140,7 +124,7 @@ public void whenDeserializingUsingJsonInject_thenCorrect() throws JsonProcessing
140124 }
141125
142126 @ Test
143- public void whenDeserializingUsingJsonAnySetter_thenCorrect () throws JsonProcessingException , IOException {
127+ public void whenDeserializingUsingJsonAnySetter_thenCorrect () throws IOException {
144128 final String json = "{\" name\" :\" My bean\" ,\" attr2\" :\" val2\" ,\" attr1\" :\" val1\" }" ;
145129
146130 final ExtendableBean bean = new ObjectMapper ().readerFor (ExtendableBean .class ).readValue (json );
@@ -149,15 +133,15 @@ public void whenDeserializingUsingJsonAnySetter_thenCorrect() throws JsonProcess
149133 }
150134
151135 @ Test
152- public void whenDeserializingUsingJsonSetter_thenCorrect () throws JsonProcessingException , IOException {
136+ public void whenDeserializingUsingJsonSetter_thenCorrect () throws IOException {
153137 final String json = "{\" id\" :1,\" name\" :\" My bean\" }" ;
154138
155139 final BeanWithGetter bean = new ObjectMapper ().readerFor (BeanWithGetter .class ).readValue (json );
156140 assertEquals ("My bean" , bean .getTheName ());
157141 }
158142
159143 @ Test
160- public void whenDeserializingUsingJsonDeserialize_thenCorrect () throws JsonProcessingException , IOException {
144+ public void whenDeserializingUsingJsonDeserialize_thenCorrect () throws IOException {
161145 final String json = "{\" name\" :\" party\" ,\" eventDate\" :\" 20-12-2014 02:30:00\" }" ;
162146
163147 final SimpleDateFormat df = new SimpleDateFormat ("dd-MM-yyyy hh:mm:ss" );
@@ -169,7 +153,7 @@ public void whenDeserializingUsingJsonDeserialize_thenCorrect() throws JsonProce
169153 // ========================= Inclusion annotations ============================
170154
171155 @ Test
172- public void whenSerializingUsingJsonIgnoreProperties_thenCorrect () throws JsonProcessingException , IOException {
156+ public void whenSerializingUsingJsonIgnoreProperties_thenCorrect () throws IOException {
173157 final BeanWithIgnore bean = new BeanWithIgnore (1 , "My bean" );
174158
175159 final String result = new ObjectMapper ().writeValueAsString (bean );
@@ -178,7 +162,7 @@ public void whenSerializingUsingJsonIgnoreProperties_thenCorrect() throws JsonPr
178162 }
179163
180164 @ Test
181- public void whenSerializingUsingJsonIgnore_thenCorrect () throws JsonProcessingException , IOException {
165+ public void whenSerializingUsingJsonIgnore_thenCorrect () throws IOException {
182166 final BeanWithIgnore bean = new BeanWithIgnore (1 , "My bean" );
183167
184168 final String result = new ObjectMapper ().writeValueAsString (bean );
@@ -199,7 +183,7 @@ public void whenSerializingUsingJsonIgnoreType_thenCorrect() throws JsonProcessi
199183 }
200184
201185 @ Test
202- public void whenSerializingUsingJsonInclude_thenCorrect () throws JsonProcessingException , IOException {
186+ public void whenSerializingUsingJsonInclude_thenCorrect () throws IOException {
203187 final MyBean bean = new MyBean (1 , null );
204188
205189 final String result = new ObjectMapper ().writeValueAsString (bean );
@@ -208,7 +192,7 @@ public void whenSerializingUsingJsonInclude_thenCorrect() throws JsonProcessingE
208192 }
209193
210194 @ Test
211- public void whenSerializingUsingJsonAutoDetect_thenCorrect () throws JsonProcessingException , IOException {
195+ public void whenSerializingUsingJsonAutoDetect_thenCorrect () throws IOException {
212196 final PrivateBean bean = new PrivateBean (1 , "My bean" );
213197
214198 final String result = new ObjectMapper ().writeValueAsString (bean );
@@ -219,7 +203,7 @@ public void whenSerializingUsingJsonAutoDetect_thenCorrect() throws JsonProcessi
219203 // ========================= Polymorphic annotations ============================
220204
221205 @ Test
222- public void whenSerializingPolymorphic_thenCorrect () throws JsonProcessingException , IOException {
206+ public void whenSerializingPolymorphic_thenCorrect () throws IOException {
223207 final Zoo .Dog dog = new Zoo .Dog ("lacy" );
224208 final Zoo zoo = new Zoo (dog );
225209
@@ -230,7 +214,7 @@ public void whenSerializingPolymorphic_thenCorrect() throws JsonProcessingExcept
230214 }
231215
232216 @ Test
233- public void whenDeserializingPolymorphic_thenCorrect () throws JsonProcessingException , IOException {
217+ public void whenDeserializingPolymorphic_thenCorrect () throws IOException {
234218 final String json = "{\" animal\" :{\" name\" :\" lacy\" ,\" type\" :\" cat\" }}" ;
235219
236220 final Zoo zoo = new ObjectMapper ().readerFor (Zoo .class ).readValue (json );
@@ -352,7 +336,7 @@ public void whenSerializingUsingMixInAnnotation_thenCorrect() throws JsonProcess
352336 }
353337
354338 @ Test
355- public void whenDisablingAllAnnotations_thenAllDisabled () throws JsonProcessingException , IOException {
339+ public void whenDisablingAllAnnotations_thenAllDisabled () throws IOException {
356340 final MyBean bean = new MyBean (1 , null );
357341
358342 final ObjectMapper mapper = new ObjectMapper ();
0 commit comments