Introducing DTOs

So far, we haven't created any data transfer objects (DTOs). It is time to do so. We will introduce two more fields. Extend the Note and Todo classes. Add created and modified fields:

  • Note:
package com.journaler.api.data 
 
import com.fasterxml.jackson.annotation.JsonInclude 
import org.hibernate.annotations.CreationTimestamp 
import org.hibernate.annotations.GenericGenerator 
import org.hibernate.annotations.UpdateTimestamp 
import java.util.* 
import javax.persistence.* 
 
@Entity 
@Table(name = "note") 
@JsonInclude(JsonInclude.Include.NON_NULL) 
data class Note( 
        ... 
        @CreationTimestamp 
        var created: Date = Date(), 
        @UpdateTimestamp 
        var modified: Date = Date() 
) { 
    ... 
} 
  • Todo:
package com.journaler.api.data import com.fasterxml.jackson.annotation.JsonInclude ...

Get Building Applications with Spring 5 and Kotlin now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.