6

I stored the java object in hbase (i.e) Let's say I have an object 'User' with 3 parameters like firstname, middlename and lastname. I used the following code for serialization in java

Object object = (object) user;    
byte[] byteData = SerializationUtils.serialize((Serializable) object);

and stored in hbase like 'storing complete object (in byte[] format of above) in the Value portion of the KeyValue pair'

It is stored in hbase like (Example)

column=container:container, timestamp=1480016194005, value=\xAC\xED\x00\x05sr\x00&com.test.container\x07\x89\x83\xFA\x7F\xD0F\xA5\x02\x00\x08I\x00\x07classIdJ\x00\x14dateTimeInLongFormatZ\x00\x04rootZ\x00\x09undefinedL\x00\x03keyt\x00\x12Ljava/lang/String;L\x00\x04modeq\x00~\x00\x01L\x00\x04nameq\x00~\x00\x01L\x00\x06userIdq\x00~\x00\x01xp\x00\x00\x00\x02\x00\x00\x01X\x967\xBA\xF0\x00\x00t\x00\x1Econtainer_393_5639181044834024t\x00\x06expandt\x00\x02ert\x00\x08testadmin

when I try to retrieve the data, I used the following deserialization in java and converted back to object of readable format

object = SerializationUtils.deserialize(bytes);

I would like to retrieve the data stored in java format via happybase using python and I achieved it and received the data as available in hbase.

Is there a way to deserialize the java object via python?

1
  • Short answer: if you're asking this question then no. Longer answer: the Java binary serialization format is well specified so you could write code in Python, or any language, to read the data. But you obviously cannot create the same behaviour in Python code an in Java code so whilst you can read the data from the serialized format, you cannot read the behaviour. Commented Nov 25, 2016 at 16:23

1 Answer 1

10

There is a Python 3 library for that:

https://pypi.python.org/pypi/javaobj-py3

Usage seems pretty easy with:

from pathlib import Path

import javaobj

jobj = Path('…').read_bytes()
pobj = javaobj.loads(jobj)
print(pobj)
Sign up to request clarification or add additional context in comments.

3 Comments

By using pyobj = javaobj.loads(data) I am converting b"" to object but sometimes I am getting error RuntimeError: Stream has been ended unexpectedly while unmarshaling.. Do you know any reason?
I'm getting error on read_file; This method is not defined. What am I missing?
That method doesn't exist in Python, you will have to define it yourself

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.