-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
08ee53c
commit 3171739
Showing
1 changed file
with
52 additions
and
1 deletion.
There are no files selected for viewing
53 changes: 52 additions & 1 deletion
53
src/main/java/tk/dmanstrator/sb3_serialization_test/entity/CustomObject.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,57 @@ | ||
package tk.dmanstrator.sb3_serialization_test.entity; | ||
|
||
import java.io.Serial; | ||
import java.io.Serializable; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
public record CustomObject(String hello, List<String> world) implements Serializable {} | ||
public class CustomObject implements Serializable { | ||
|
||
@Serial | ||
private static final long serialVersionUID = 0L; | ||
|
||
private final String hello; | ||
private final List<String> world; | ||
|
||
// Default Constructor needed for (de)serialization. | ||
public CustomObject() { | ||
this("", new ArrayList<>()); | ||
} | ||
|
||
public CustomObject(String hello, List<String> world) { | ||
this.hello = hello; | ||
this.world = world; | ||
} | ||
|
||
public String getHello() { | ||
return hello; | ||
} | ||
|
||
public List<String> getWorld() { | ||
return world; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (obj == this) return true; | ||
if (obj == null || obj.getClass() != this.getClass()) return false; | ||
var that = (CustomObject) obj; | ||
return Objects.equals(this.hello, that.hello) && | ||
Objects.equals(this.world, that.world); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(hello, world); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "CustomObject{" + | ||
"hello='" + hello + '\'' + | ||
", world=" + world + | ||
'}'; | ||
} | ||
|
||
} |