javaobj-py3 is a Python library designed for serializing and de-serializing Java objects, facilitating interoperability between Python and Java applications. It is currently at version 0.4.4 and receives irregular but active updates, with the latest significant features and fixes released recently.
Install & Compatibility
Where this runs
tested against v0.5.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.920 runs
installs and imports cleanly · install 0.0s · import 0.042s · 18.4MB
glibcpy 3.10–3.920 runs
installs and imports cleanly · install 1.6s · import 0.036s · 19MB
16MB installed
● package 16MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
from javaobj import loads
Only available with the default 'v1' parser; the 'v2' parser does not support serialization.
from javaobj import dumps
Represents a deserialized custom Java object or can be used to construct objects for serialization.
from javaobj import JavaObject
The more robust 'v2' deserializer, recommended for complex Java streams, but it cannot serialize.
from javaobj.v2 import loads as v2_loads
This quickstart demonstrates how to deserialize common Java types (String, List) into their Python equivalents using `javaobj.loads()`. It also shows a basic example of serializing a Python string to Java format using `javaobj.dumps()` and introduces the `v2_loads` parser for advanced deserialization.
import javaobj
# 1. Deserializing a simple Java String
# Bytes represent a serialized Java String "Hello, World!"
java_serialized_string = b'\xac\xed\x00\x05t\x00\x0cHello, World!'
python_string = javaobj.loads(java_serialized_string)
print(f"Deserialized Java String: '{python_string}' (Python type: {type(python_string)})")
# 2. Deserializing a Java object that maps to a Python list
# Bytes for a serialized Java ArrayList containing "One" and "Two"
java_list_bytes = b'\xac\xed\x00\x05sr\x00\x13java.util.ArrayListx\x81\xd2\x1d\x99\xc7\xed\x11\x00\x02\x00\x00xp\x00\x00\x00\x02w\x04\x00\x00\x00\x02t\x00\x03Onet\x00\x03Twoe\x00'
python_list = javaobj.loads(java_list_bytes)
print(f"Deserialized Java List: {python_list} (Python type: {type(python_list)})")
# 3. Basic Serialization (available via the default v1 implementation)
# Serializing a Python string back into Java format
serialized_bytes = javaobj.dumps("Python data")
print(f"Serialized 'Python data' (first 20 bytes): {serialized_bytes[:20]}...")
# 4. Deserializing using the v2 parser for potentially better compatibility
# (Note: For this simple string, output will be identical)
from javaobj.v2 import loads as v2_loads
python_string_v2 = v2_loads(java_serialized_string)
print(f"Deserialized (v2) Java String: '{python_string_v2}' (Python type: {type(python_string_v2)})")
Upgrade
Version history
Breaking-change detection hasn't run for this library yet.
Audit
Security & dependencies
CVE tracking and dependency tree are planned for a later release.