JAVA-17420 Update The transient Keyword in Java Article (#13321)
Co-authored-by: Iulian Timis <iulian.timis@tora.com>
This commit is contained in:
parent
0162d98907
commit
ea9bf9ebeb
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue