JAVA-17420 Update The transient Keyword in Java Article (#13321)

Co-authored-by: Iulian Timis <iulian.timis@tora.com>
This commit is contained in:
timis1 2023-01-23 20:27:35 +02:00 committed by GitHub
parent 0162d98907
commit ea9bf9ebeb
2 changed files with 16 additions and 1 deletions

View File

@ -11,6 +11,8 @@ public class Book implements Serializable {
private transient int copies;
private final transient String bookCategory = "Fiction";
private final transient String bookCategoryNewOperator = new String("Fiction with new Operator");
public String getBookName() {
return bookName;
}
@ -39,4 +41,7 @@ public class Book implements Serializable {
return bookCategory;
}
public String getBookCategoryNewOperator() {
return bookCategoryNewOperator;
}
}

View File

@ -34,7 +34,17 @@ class TransientUnitTest {
assertEquals("Fiction", book2.getBookCategory());
}
@Test
void givenFinalTransientWithNewOperator_whenSerDe_thenValuePersisted() throws Exception {
Book book = new Book();
BookSerDe.serialize(book);
Book book2 = BookSerDe.deserialize();
assertNull(book2.getBookCategoryNewOperator());
}
@AfterAll
public static void cleanup() {
File file = new File(BookSerDe.fileName);