Skip to content

Commit 26c67aa

Browse files
authored
Merge pull request #10 from voetsjoeba/master
Fixed byte[] member fields getting serialized as TC_OBJECT instead of TC_ARRAY
2 parents cc1353c + e710b96 commit 26c67aa

File tree

4 files changed

+24
-0
lines changed

4 files changed

+24
-0
lines changed

javaobj.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1357,6 +1357,8 @@ def _write_value(self, field_type, value):
13571357
self.write_null()
13581358
elif isinstance(value, JavaEnum):
13591359
self.write_enum(value)
1360+
elif isinstance(value, JavaArray):
1361+
self.write_array(value)
13601362
elif isinstance(value, JavaObject):
13611363
self.write_object(value)
13621364
elif isinstance(value, JavaString):

tests/java/src/test/java/OneTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ class ClassWithEnum implements Serializable {
2626
public Color[] colors = { Color.GREEN, Color.BLUE, Color.RED };
2727
}
2828

29+
class ClassWithByteArray implements Serializable {
30+
private static final long serialVersionUID = 1L;
31+
public byte[] myArray = new byte[]{1,3,7,11};
32+
}
33+
2934
enum Color {
3035
BLUE("BLUE"), GREEN("GREEN"), RED("RED"), UNKNOWN("UNKNOWN");
3136
private final String value;
@@ -221,6 +226,13 @@ public void testException() throws Exception {
221226
}
222227
}
223228

229+
@Test
230+
public void testClassWithByteArray() throws Exception {
231+
final ClassWithByteArray cwba = new ClassWithByteArray();
232+
oos.writeObject(cwba);
233+
oos.flush();
234+
}
235+
224236
@Test
225237
public void testSuper() throws Exception {
226238
oos = new ObjectOutputStream(fos = new FileOutputStream("objSuper.ser"));

tests/testClassWithByteArray.ser

81 Bytes
Binary file not shown.

tests/tests.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,16 @@ def test_bytes_rw(self):
129129
jobj_ = javaobj.dumps(pobj)
130130
self.assertEqual(jobj, jobj_)
131131

132+
def test_class_with_byte_array_rw(self):
133+
jobj = self.read_file("testClassWithByteArray.ser")
134+
pobj = javaobj.loads(jobj)
135+
136+
self.assertEqual(pobj.myArray, [1,3,7,11])
137+
138+
jobj_ = javaobj.dumps(pobj)
139+
javaobj.loads(jobj_)
140+
self.assertEqual(jobj, jobj_)
141+
132142
def test_boolean(self):
133143
"""
134144
Reads testBoolean.ser and checks the serialization process

0 commit comments

Comments
 (0)