I am trying to develop team management software. I have a Team object:
public class Team implements Serializable{
private String name;
private ArrayList<Player> teamMembers;
private String sport;
private ArrayList<Staff> staff;
private Object schedule;
private String teamHometown;
private String teamState;
public Team(String name, String sport, ArrayList<Player> players, ArrayList<Staff> staff){
teamMembers = players;
this.staff = staff;
this.sport =(sport);
this.name = (name);
}
}
The command object contains an ArrayList of Player objects. In each Player object, a player has many attributes, such as a name, statistics, and a photo of the player (buffered image):
public class Player implements Serializable{
private BufferedImage playerPhoto;
private String firstName;
private String lastName;
private int jerseyNumber;
private String playerPosition;
private String status;
private int gameAbscenses;
private int goals;
private int appearances;
private int yellowCards;
private int redCards;
private LocalDate birthday;
private boolean starter;
private int shots;
private int shotsOnGoal;
private int assists;
public Player(String firstName, String lastName, int jerseyNumber, String playerPosition,BufferedImage playerPhoto) {
this.firstName = (firstName);
this.lastName = (lastName);
this.jerseyNumber = (jerseyNumber);
this.playerPosition = (playerPosition);
this.gameAbscenses = (0);
this.status = ("Healthy");
this.starter = false;
this.shots = (0);
this.appearances = (0);
this.shotsOnGoal = (0);
this.redCards = (0);
this.yellowCards = (0);
this.assists = (0);
this.goals = (0);
this.birthday = LocalDate.now();
}
My goal is to serialize an array of Team objects, but the buffered images are not serializable, and since the Player object contains a buffer image as one of its private instance variables, I cannot serialize ArrayList of Team objects.
I initially tried to do this:
ArrayList<Team> finalTeams = new ArrayList<>(SignInController.userTeams);
FileOutputStream fos = new FileOutputStream(SignInController.userfname+" Teams/"+SignInController.userfname+"_teams.xtm");
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(finalTeams);
oos.close();
fos.close();
. , , .
- , , ! !