|
| 1 | +# javaobj-py3 |
| 2 | + |
| 3 | +python-javaobj is a python library that provides functions for reading and |
| 4 | +writing (writing is WIP currently) Java objects serialized or will be |
| 5 | +deserialized by _ObjectOutputStream_. This form of object representation is a |
| 6 | +standard data interchange format in Java world. |
| 7 | + |
| 8 | +javaobj module exposes an API familiar to users of the standard library |
| 9 | +marshal, pickle and json modules. |
| 10 | + |
| 11 | +## About this repository |
| 12 | + |
| 13 | +This project is a fork of python-javaobj by Volodymyr Buell, originally from |
| 14 | +[Google Code](http://code.google.com/p/python-javaobj/) and now hosted on |
| 15 | +[GitHub](https://github.com/vbuell/python-javaobj). |
| 16 | + |
| 17 | +This fork intends to work both on Python 2.7 and Python 3. |
| 18 | + |
| 19 | +## Features |
| 20 | + |
| 21 | + * Java object instance unmarshaling |
| 22 | + * Java classes unmarshaling |
| 23 | + * Primitive values unmarshaling |
| 24 | + * Automatic conversion of Java Collections to python ones |
| 25 | + (_HashMap_ => dict, _ArrayList_ => list, etc) |
| 26 | + |
| 27 | +## Requirements |
| 28 | + |
| 29 | + * Python >= 2.6, but < 3.0 (porting to 3.0 is in progress) |
| 30 | + * Maven 2+ (for building test data of serialized objects. |
| 31 | + You can skip it if you do not plan to run tests.py) |
| 32 | + |
| 33 | +## Usage |
| 34 | + |
| 35 | +Unmarshalling of Java serialised object: |
| 36 | + |
| 37 | +```python |
| 38 | +import javaobj |
| 39 | + |
| 40 | +jobj = self.read_file("obj5.ser") |
| 41 | +pobj = javaobj.loads(jobj) |
| 42 | +print pobj |
| 43 | +``` |
| 44 | + |
| 45 | +Or, you can use Unmarshaller object directly: |
| 46 | + |
| 47 | +```python |
| 48 | +import javaobj |
| 49 | + |
| 50 | +marshaller = javaobj.JavaObjectUnmarshaller(open("sunExample.ser")) |
| 51 | +pobj = marshaller.readObject() |
| 52 | + |
| 53 | +self.assertEqual(pobj.value, 17) |
| 54 | +self.assertTrue(pobj.next) |
| 55 | + |
| 56 | +pobj = marshaller.readObject() |
| 57 | +``` |
0 commit comments