-
Notifications
You must be signed in to change notification settings - Fork 232
[BEANUTILS-417] Refactor serialization methods to conform to Java Object Serialization Specification #430
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 1.X
Are you sure you want to change the base?
[BEANUTILS-417] Refactor serialization methods to conform to Java Object Serialization Specification #430
Changes from all commits
de7ae87
7370240
2ce79e2
ceb91fd
eb2d854
c8e1ede
2c2a6b6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ | |
| .settings/ | ||
| /site-content/ | ||
| /.idea/ | ||
| *.iml | ||
|
|
||
| # NetBeans files | ||
| nb-configuration.xml | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,14 +32,14 @@ | |
| * for use by mapped and iterated properties. | ||
| * A mapped or iterated property may choose to indicate the type it expects. | ||
| * The DynaBean implementation may choose to enforce this type on its entries. | ||
| * Alternatively, an implementatin may choose to ignore this property. | ||
| * All keys for maps must be of type String so no meta data is needed for map keys.</p> | ||
| * Alternatively, an implementation may choose to ignore this property. | ||
| * All keys for maps must be of type String so no metadata is needed for map keys.</p> | ||
| * | ||
| */ | ||
|
|
||
| public class DynaProperty implements Serializable { | ||
|
|
||
| private static final long serialVersionUID = 1L; | ||
| private static final long serialVersionUID = 2L; | ||
| /* | ||
| * There are issues with serializing primitive class types on certain JVM versions | ||
| * (including java 1.3). | ||
|
|
@@ -111,7 +111,7 @@ public DynaProperty(final String name, final Class<?> type, final Class<?> conte | |
|
|
||
| /** | ||
| * Checks this instance against the specified Object for equality. Overrides the | ||
| * default refererence test for equality provided by {@link Object#equals(Object)} | ||
| * default reference test for equality provided by {@link Object#equals(Object)} | ||
| * | ||
| * @param obj The object to compare to | ||
| * @return {@code true} if object is a dyna property with the same name | ||
|
|
@@ -121,9 +121,7 @@ public DynaProperty(final String name, final Class<?> type, final Class<?> conte | |
| @Override | ||
| public boolean equals(final Object obj) { | ||
|
|
||
| boolean result = false; | ||
|
|
||
| result = obj == this; | ||
| boolean result = obj == this; | ||
|
|
||
| if (!result && obj instanceof DynaProperty) { | ||
| final DynaProperty that = (DynaProperty) obj; | ||
|
|
@@ -145,7 +143,7 @@ public boolean equals(final Object obj) { | |
| * Therefore, this field <strong>must not be serialized using the standard methods</strong>.</p> | ||
| * | ||
| * @return The Class for the content type if this is an indexed {@code DynaProperty} | ||
| * and this feature is supported. Otherwise null. | ||
| * and this feature is supported. Otherwise, null. | ||
| */ | ||
| public Class<?> getContentType() { | ||
| return contentType; | ||
|
|
@@ -247,8 +245,7 @@ private Class<?> readAnyClass(final ObjectInputStream in) throws IOException, Cl | |
| default: | ||
| // something's gone wrong | ||
| throw new StreamCorruptedException( | ||
| "Invalid primitive type. " | ||
| + "Check version of beanutils used to serialize is compatible."); | ||
| "Invalid primitive type. Check version of beanutils used to serialize is compatible."); | ||
|
|
||
| } | ||
| } | ||
|
|
@@ -262,12 +259,14 @@ private Class<?> readAnyClass(final ObjectInputStream in) throws IOException, Cl | |
| * @throws ClassNotFoundException Class of a serialized object cannot be found. | ||
| */ | ||
| private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException { | ||
| // read default first (as defined by the Java Object Serialization Specification) | ||
| in.defaultReadObject(); | ||
|
|
||
| // read custom values | ||
| this.type = readAnyClass(in); | ||
| if (isMapped() || isIndexed()) { | ||
| this.contentType = readAnyClass(in); | ||
| } | ||
| // read other values | ||
| in.defaultReadObject(); | ||
| } | ||
|
Comment on lines
261
to
270
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll just bump serialVersionUID, as supporting both serialization strategies is non-trivial to impossible. |
||
|
|
||
| /** | ||
|
|
@@ -333,11 +332,13 @@ private void writeAnyClass(final Class<?> clazz, final ObjectOutputStream out) t | |
| * @throws IOException if I/O errors occur while writing to the underlying stream. | ||
| */ | ||
| private void writeObject(final ObjectOutputStream out) throws IOException { | ||
| writeAnyClass(this.type,out); | ||
| // write out default first (as defined by the Java Object Serialization Specification) | ||
| out.defaultWriteObject(); | ||
|
|
||
| // write custom values | ||
| writeAnyClass(this.type, out); | ||
| if (isMapped() || isIndexed()) { | ||
| writeAnyClass(this.contentType,out); | ||
| writeAnyClass(this.contentType, out); | ||
| } | ||
| // write out other values | ||
| out.defaultWriteObject(); | ||
| } | ||
|
Comment on lines
334
to
343
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. writeObject() wouldn't need to be adapted, as we want to write the new format always. However, I'll just bump serialVersionUID, as supporting both serialization strategies is non-trivial to impossible. |
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.