77import java .io .IOException ;
88import java .util .List ;
99
10- import org .baeldung .jackson .MyBooleanMixIn ;
10+ import org .baeldung .jackson .MyMixInForString ;
1111import org .baeldung .jackson .MyDto ;
12+ import org .baeldung .jackson .MyDtoIgnoreField ;
1213import org .baeldung .jackson .MyDtoIgnoreFieldByName ;
1314import org .baeldung .jackson .MyDtoIncludeNonDefault ;
1415import org .junit .Test ;
@@ -43,7 +44,7 @@ public final void givenOnlyNonDefaultValuesAreSerialized_whenDtoHasNonDefaultVal
4344 }
4445
4546 @ Test
46- public final void givenFieldIsIgnored_whenDtoIsSerialized_thenCorrect () throws JsonParseException , IOException {
47+ public final void givenFieldIsIgnoredByName_whenDtoIsSerialized_thenCorrect () throws JsonParseException , IOException {
4748 final ObjectMapper mapper = new ObjectMapper ();
4849 final MyDtoIgnoreFieldByName dtoObject = new MyDtoIgnoreFieldByName ();
4950 dtoObject .setBooleanValue (true );
@@ -55,10 +56,22 @@ public final void givenFieldIsIgnored_whenDtoIsSerialized_thenCorrect() throws J
5556 System .out .println (dtoAsString );
5657 }
5758
59+ @ Test
60+ public final void givenFieldIsIgnoredDirectly_whenDtoIsSerialized_thenCorrect () throws JsonParseException , IOException {
61+ final ObjectMapper mapper = new ObjectMapper ();
62+ final MyDtoIgnoreField dtoObject = new MyDtoIgnoreField ();
63+
64+ final String dtoAsString = mapper .writeValueAsString (dtoObject );
65+
66+ assertThat (dtoAsString , not (containsString ("intValue" )));
67+ assertThat (dtoAsString , containsString ("booleanValue" ));
68+ System .out .println (dtoAsString );
69+ }
70+
5871 @ Test
5972 public final void givenFieldTypeIsIgnored_whenDtoIsSerialized_thenCorrect () throws JsonParseException , IOException {
6073 final ObjectMapper mapper = new ObjectMapper ();
61- mapper .addMixInAnnotations (String .class , MyBooleanMixIn .class );
74+ mapper .addMixInAnnotations (String .class , MyMixInForString .class );
6275 final MyDto dtoObject = new MyDto ();
6376 dtoObject .setBooleanValue (true );
6477
0 commit comments