Skip to content

urucoder/python-javaobj

Repository files navigation

javaobj-py3

Latest Version License Travis-CI status Coveralls status

python-javaobj is a python library that provides functions for reading and writing (writing is WIP currently) Java objects serialized or will be deserialized by ObjectOutputStream. This form of object representation is a standard data interchange format in Java world.

The javaobj module exposes an API familiar to users of the standard library marshal, pickle and json modules.

About this repository

This project is a fork of python-javaobj by Volodymyr Buell, originally from Google Code and now hosted on GitHub.

This fork intends to work both on Python 2.7 and Python 3.4+.

Compatibility warning: New version of the parser

Since version 0.4.0, two implementations of the parser are available:

  • v1: the classic implementation of javaobj, with a work in progress implementation of a writer.
  • v2: the new implementation, a port of jdeserialize with support of the object transformer (with a new API) and the numpy arrays.

Compatibility Warning: object transformer

As of version 0.2.0, the notion of object transformer from the original project as been replaced by an object creator.

The object creator is called before the deserialization. This allows to store the reference of the converted object before deserializing it, and avoids a mismatch between the referenced object and the transformed one.

Compatibility Warning: bytes arrays

As of version 0.2.3, bytes arrays are loaded as a bytes object instead of an array of integers.

Features

  • Java object instance unmarshaling
  • Java classes unmarshaling
  • Primitive values unmarshaling
  • Automatic conversion of Java Collections to python ones (HashMap => dict, ArrayList => list, etc.)
  • Basic marshalling of simple Java objects

Requirements

  • Python >= 2.7 or Python >= 3.4
  • enum34 and typing when using Python <= 3.4 (installable with pip)
  • Maven 2+ (for building test data of serialized objects. You can skip it if you do not plan to run tests.py)

Usage (V1 implementation)

Unmarshalling of Java serialised object:

import javaobj

with open("obj5.ser", "rb") as fd:
    jobj = fd.read()

pobj = javaobj.loads(jobj)
print(pobj)

Or, you can use Unmarshaller object directly:

import javaobj

with open("objCollections.ser", "rb") as fd:
    marshaller = javaobj.JavaObjectUnmarshaller(fd)
    pobj = marshaller.readObject()

    print(pobj.value, "should be", 17)
    print(pobj.next, "should be", True)

    pobj = marshaller.readObject()

The objects and methods provided by javaobj module are shortcuts to the javaobj.v1 package

Usage (V2 implementation)

Unmarshalling of Java serialised object:

import javaobj.v2 as javaobj

with open("obj5.ser", "rb") as fd:
    jobj = fd.read()

pobj = javaobj.loads(jobj)
print(pobj)

Object Transformer

WIP

About

Extended fork of python-javaobj from http://code.google.com/p/python-javaobj/

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages

  • Python 92.5%
  • Java 7.5%