Closed voetsjoeba closed 8 years ago
Adding a missing elif for the JavaArray
case to JavaObjectMarshaller._write_value
appears to solve the issue, although I can't be sure if that's a good fix since it's also used in other circumstances:
diff --git a/javaobj.py b/javaobj.py
index 38f49d5..25f7b07 100644
--- a/javaobj.py
+++ b/javaobj.py
@@ -1357,6 +1357,8 @@ class JavaObjectMarshaller(JavaObjectConstants):
self.write_null()
elif isinstance(value, JavaEnum):
self.write_enum(value)
+ elif isinstance(value, JavaArray):
+ self.write_array(value)
elif isinstance(value, JavaObject):
self.write_object(value)
elif isinstance(value, JavaString):
OK, the bug can be easily reproduced and your fix works as intented. I don't have a real-life usage of this kind of operation (writing arrays) but the specific handling of JavaArray objects was obviously missing.
Do you want to make a pull request with your fix ?
If you're ok with the fix, sure. Will get one prepared and submitted.
PR merged, thanks !
While experimenting with the writing functionality of javaobj, I found that when serializing member fields of an object of type byte[], they are written as TC_OBJECTs instead TC_ARRAYs.
Here's a failing test case to reproduce: In
tests/java/src/test/java/OneTest.java
:In
tests/tests.py
:The assertEqual at the end fails. Re-reading the result of dumps with loads shows that the
myArray
field was written as a TC_OBJECT instead of a TC_ARRAY: