1212import java .util .Date ;
1313import java .util .TimeZone ;
1414
15- import com .baeldung .jackson .bidirection .ItemWithIdentity ;
16- import com .baeldung .jackson .bidirection .ItemWithRef ;
17- import com .baeldung .jackson .bidirection .UserWithRef ;
18- import com .baeldung .jackson .dtos .User ;
19- import com .baeldung .jackson .dtos .withEnum .TypeEnumWithValue ;
15+ import org .junit .Test ;
16+
2017import com .baeldung .jackson .annotation .BeanWithCreator ;
2118import com .baeldung .jackson .annotation .BeanWithCustomAnnotation ;
2219import com .baeldung .jackson .annotation .BeanWithFilter ;
3027import com .baeldung .jackson .annotation .UnwrappedUser ;
3128import com .baeldung .jackson .annotation .UserWithIgnoreType ;
3229import com .baeldung .jackson .annotation .Zoo ;
30+ import com .baeldung .jackson .bidirection .ItemWithIdentity ;
31+ import com .baeldung .jackson .bidirection .ItemWithRef ;
3332import com .baeldung .jackson .bidirection .UserWithIdentity ;
33+ import com .baeldung .jackson .bidirection .UserWithRef ;
3434import com .baeldung .jackson .date .EventWithFormat ;
3535import com .baeldung .jackson .date .EventWithSerializer ;
36- import com .baeldung .jackson .dtos .MyMixInForString ;
36+ import com .baeldung .jackson .dtos .MyMixInForIgnoreType ;
37+ import com .baeldung .jackson .dtos .withEnum .TypeEnumWithValue ;
3738import com .baeldung .jackson .exception .UserWithRoot ;
3839import com .baeldung .jackson .jsonview .Item ;
3940import com .baeldung .jackson .jsonview .Views ;
40- import org .junit .Ignore ;
41- import org .junit .Test ;
42-
4341import com .fasterxml .jackson .core .JsonParseException ;
4442import com .fasterxml .jackson .core .JsonProcessingException ;
4543import com .fasterxml .jackson .databind .InjectableValues ;
@@ -127,7 +125,7 @@ public void whenSerializingUsingJsonSerialize_thenCorrect() throws JsonProcessin
127125 public void whenDeserializingUsingJsonCreator_thenCorrect () throws JsonProcessingException , IOException {
128126 final String json = "{\" id\" :1,\" theName\" :\" My bean\" }" ;
129127
130- final BeanWithCreator bean = new ObjectMapper ().reader (BeanWithCreator .class ).readValue (json );
128+ final BeanWithCreator bean = new ObjectMapper ().readerFor (BeanWithCreator .class ).readValue (json );
131129 assertEquals ("My bean" , bean .name );
132130 }
133131
@@ -136,7 +134,7 @@ public void whenDeserializingUsingJsonInject_thenCorrect() throws JsonProcessing
136134 final String json = "{\" name\" :\" My bean\" }" ;
137135 final InjectableValues inject = new InjectableValues .Std ().addValue (int .class , 1 );
138136
139- final BeanWithInject bean = new ObjectMapper ().reader (inject ).withType (BeanWithInject .class ).readValue (json );
137+ final BeanWithInject bean = new ObjectMapper ().reader (inject ).forType (BeanWithInject .class ).readValue (json );
140138 assertEquals ("My bean" , bean .name );
141139 assertEquals (1 , bean .id );
142140 }
@@ -145,7 +143,7 @@ public void whenDeserializingUsingJsonInject_thenCorrect() throws JsonProcessing
145143 public void whenDeserializingUsingJsonAnySetter_thenCorrect () throws JsonProcessingException , IOException {
146144 final String json = "{\" name\" :\" My bean\" ,\" attr2\" :\" val2\" ,\" attr1\" :\" val1\" }" ;
147145
148- final ExtendableBean bean = new ObjectMapper ().reader (ExtendableBean .class ).readValue (json );
146+ final ExtendableBean bean = new ObjectMapper ().readerFor (ExtendableBean .class ).readValue (json );
149147 assertEquals ("My bean" , bean .name );
150148 assertEquals ("val2" , bean .getProperties ().get ("attr2" ));
151149 }
@@ -154,7 +152,7 @@ public void whenDeserializingUsingJsonAnySetter_thenCorrect() throws JsonProcess
154152 public void whenDeserializingUsingJsonSetter_thenCorrect () throws JsonProcessingException , IOException {
155153 final String json = "{\" id\" :1,\" name\" :\" My bean\" }" ;
156154
157- final BeanWithGetter bean = new ObjectMapper ().reader (BeanWithGetter .class ).readValue (json );
155+ final BeanWithGetter bean = new ObjectMapper ().readerFor (BeanWithGetter .class ).readValue (json );
158156 assertEquals ("My bean" , bean .getTheName ());
159157 }
160158
@@ -164,7 +162,7 @@ public void whenDeserializingUsingJsonDeserialize_thenCorrect() throws JsonProce
164162
165163 final SimpleDateFormat df = new SimpleDateFormat ("dd-MM-yyyy hh:mm:ss" );
166164
167- final EventWithSerializer event = new ObjectMapper ().reader (EventWithSerializer .class ).readValue (json );
165+ final EventWithSerializer event = new ObjectMapper ().readerFor (EventWithSerializer .class ).readValue (json );
168166 assertEquals ("20-12-2014 02:30:00" , df .format (event .eventDate ));
169167 }
170168
@@ -235,7 +233,7 @@ public void whenSerializingPolymorphic_thenCorrect() throws JsonProcessingExcept
235233 public void whenDeserializingPolymorphic_thenCorrect () throws JsonProcessingException , IOException {
236234 final String json = "{\" animal\" :{\" name\" :\" lacy\" ,\" type\" :\" cat\" }}" ;
237235
238- final Zoo zoo = new ObjectMapper ().reader (). withType (Zoo .class ).readValue (json );
236+ final Zoo zoo = new ObjectMapper ().readerFor (Zoo .class ).readValue (json );
239237
240238 assertEquals ("lacy" , zoo .animal .name );
241239 assertEquals (Zoo .Cat .class , zoo .animal .getClass ());
@@ -250,7 +248,7 @@ public void whenUsingJsonProperty_thenCorrect() throws IOException {
250248 assertThat (result , containsString ("My bean" ));
251249 assertThat (result , containsString ("1" ));
252250
253- final BeanWithGetter resultBean = new ObjectMapper ().reader (BeanWithGetter .class ).readValue (result );
251+ final BeanWithGetter resultBean = new ObjectMapper ().readerFor (BeanWithGetter .class ).readValue (result );
254252 assertEquals ("My bean" , resultBean .getTheName ());
255253 }
256254
@@ -338,19 +336,19 @@ public void whenSerializingUsingCustomAnnotation_thenCorrect() throws JsonProces
338336 assertThat (result , not (containsString ("dateCreated" )));
339337 }
340338
341- @ Ignore ("Jackson 2.7.1-1 seems to have changed the API regarding mixins" )
339+ // @Ignore("Jackson 2.7.1-1 seems to have changed the API regarding mixins")
342340 @ Test
343341 public void whenSerializingUsingMixInAnnotation_thenCorrect () throws JsonProcessingException {
344- final User user = new User (1 , "John" );
342+ final com . baeldung . jackson . dtos . Item item = new com . baeldung . jackson . dtos . Item (1 , "book" , null );
345343
346- String result = new ObjectMapper ().writeValueAsString (user );
347- assertThat (result , containsString ("John " ));
344+ String result = new ObjectMapper ().writeValueAsString (item );
345+ assertThat (result , containsString ("owner " ));
348346
349347 final ObjectMapper mapper = new ObjectMapper ();
350- mapper .addMixIn (String . class , MyMixInForString .class );
348+ mapper .addMixIn (com . baeldung . jackson . dtos . User . class , MyMixInForIgnoreType .class );
351349
352- result = mapper .writeValueAsString (user );
353- assertThat (result , not (containsString ("John " )));
350+ result = mapper .writeValueAsString (item );
351+ assertThat (result , not (containsString ("owner " )));
354352 }
355353
356354 @ Test
0 commit comments