This is a problem when you try to serialize a class below using the code below that I get is an xml file below without all the lines in the class.
Class (some static values ββhave changed, but basically this), I left all the generated get \ set, but they are all there with public access modifiers.
public class NotificationConfiguration implements Serializable { public static final String PORT_KEY = "mail.smtp.port"; public static final String DEFAULT_PORT_VALUE = "587"; public static final String TTL_KEY = "mail.smtp.starttls.enable"; public static final String DEFAULT_TTL_VALUE = "true"; public static final String AUTH_KEY = "mail.smtp.auth"; public static final String DEFAULT_AUTH_VALUE = "true"; public static final String MAIL_SERVER_KEY = "mail.smtp.host"; public static final String DEFAULT_MAIL_CLIENT_HOST = "smtp.gmail.com"; public static final String DEFAULT_MAIL_CLIENT_USERNAME = "*********"; public static final String DEFAULT_MAIL_CLIENT_PASSWORD = "*********"; public static final String DEFAULT_MAIL_CLIENT_ADDRESS = "*********"; public static final String DEFAULT_ADMIN_EMAIL = "*********"; public static final long DEFAULT_MAIL_INTERVAL = 24*60*60*1000;
Code used for serialization, which also creates a folder if missing.
public void storeChanges() { try { try { File f = new File(NotificationConfiguration.SAVED_FOLDER_NAME); f.mkdir(); } catch (Exception e){} XMLEncoder encoder = new XMLEncoder( new BufferedOutputStream(new FileOutputStream(NotificationConfiguration.SAVED_FILE_NAME))); encoder.writeObject(notificationConfig); encoder.close(); System.out.println(LOG_CONFIGURATION_STORED); } catch (Exception ex) { System.out.println(LOG_CONFIGURATION_NOT_STORED + ex.getMessage()); } }
The resulting XML file with no exceptions that occur during serialization. It basically has great value.
source share