File tree Expand file tree Collapse file tree
src/main/java/nl/rdb/java_examples Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ package nl .rdb .java_examples .entities ;
2+
3+ import com .fasterxml .jackson .annotation .JsonInclude ;
4+
5+ @ JsonInclude (JsonInclude .Include .ALWAYS )
6+ public class PersonJackson extends Person {}
Original file line number Diff line number Diff line change 99import lombok .extern .slf4j .Slf4j ;
1010import nl .rdb .java_examples .entities .Address ;
1111import nl .rdb .java_examples .entities .Person ;
12+ import nl .rdb .java_examples .entities .PersonJackson ;
1213import nl .rdb .java_examples .jackson .deserializers .LocalDateTimeDeserializer ;
1314import nl .rdb .java_examples .scanner .Example ;
1415
@@ -46,6 +47,15 @@ void largeObjectToJsonSting() throws Exception {
4647 log .info ("Length {}" , test .getBytes (UTF_8 ).length );
4748 }
4849
50+ @ Example
51+ void emptyObjectToJson () throws Exception {
52+ String personJson = objectMapper .writeValueAsString (new Person ());
53+ log .info ("JSON: {}" , personJson );
54+
55+ String personJsonJackson = objectMapper .writeValueAsString (new PersonJackson ());
56+ log .info ("JSON: {}" , personJsonJackson );
57+ }
58+
4959 @ Example
5060 void dateTimeModule () throws Exception {
5161 record Test (LocalDateTime date ) {}
You can’t perform that action at this time.
0 commit comments