Jakarta EE
@Entity(name = "Book")
@Table(name = "book")
public class Book {
@Id
@GeneratedValue
private Long id;
@NaturalId
private String isbn;
private String title;
@Column(name = "published_on", columnDefinition = "date")
@Convert(converter = YearMonthDateAttributeConverter.class)
private YearMonth publishedOn;
// Getters and setters omitted for brevity
}
I want to insert Year and Month only and I'm using JakartaEE Jsonb. Localdate is working fine but i have to insert the day too. I don't wont to use Jackson.
public class Book {
public String isbn;
public String title;
public YearMonth publishedOn;
}
public static void main(String[] args) {
// Create a book instance
Book book = new Book();
book.isbn = "123";
book.title = "Advanced JPA and Hibernate";
book.publishedOn = YearMonth.of(2022, 9);
// Create Jsonb and serialize
Jsonb jsonb = JsonbBuilder.create();
var result = jsonb.toJson(book);
}