Skip to content

Custom transformer - create_instance invoked incorrectly? #54

Description

@UnitedMarsupials

Hello!

I'm trying to parse a file serializing an ArrayList of custom functions -- and I cannot even get the basics going...

Below is my entire script. Without the default value (such as None) for the class_desc, I get an error:

 File "/home/mi/.local/lib/python3.9/site-packages/javaobj/v2/core.py", line 528, in _do_object
instance = self._create_instance(class_desc)
File "/home/mi/.local/lib/python3.9/site-packages/javaobj/v2/core.py", line 503, in _create_instance
instance = transformer.create_instance(class_desc)
TypeError: create_instance() missing 1 required positional argument: 'class_desc'

If I put the default value, the call to create_instance goes through, and the method prints the value of self, which indicates, that it is the class_desc -- instead of referring to the transformer:

INFO:javaobj.parser:Reading next content
DEBUG:javaobj.parser:Reading new object: handle 7e0001, classdesc [classdesc 0x7e0000: name java.util.ArrayList, uid 8683452581122892189]
Self is [classdesc 0x7e0000: name java.util.ArrayList, uid 8683452581122892189], class_desc is None
Traceback ...

Please, advise. Thank you!

importjavaobj.v2asjavaobjimportsysimportosimportjsonimportpprintimportlogginglogging.basicConfig(level=logging.DEBUG)
classodrnavsFunctionInstance(javaobj.beans.JavaInstance):
def__init__(self):
javaobj.beans.JavaInstance.__init__(self)
defload_from_instance(self):
ifnotself.classdescorself.classdescnotinself.field_data:
returnFalsefields=self.classdesc.fields_namesvalues= [
self.field_data[self.classdesc][self.classdesc.fields[i]]
foriinrange(len(fields))
]
self.field_data=dict(zip(fields, values))
ifnotself.classdesc.super_classor \
self.classdesc.super_classnotinself.annotations:
returnTruesuper_class=self.annotations[self.classdesc.super_class][0]
self.annotations=dict(zip(super_class.fields_names, super_class.field_data))
returnTrueclassodrnavsTransformer(javaobj.transformers.ObjectTransformer):
def__init__(self, handled_classes= {
'my.apps.datalayer.client.navs.shared.api.Function':
odrnavsFunctionInstance
}):
super(JavaRandomTransformer, self).__init__()
self.instance=Noneself.handled_classes=handled_classesor {}
defcreate_instance(self, class_desc=None):
print('Self is %s, class_desc is %s'% (self, class_desc))
ifclass_desc.namenotinself.handled_classes:
returnNoneself.instance=self.handled_classes[class_desc.name]()
returnself.instanceifsys.argv[1].endswith('.gz'):
importgzipopener=gzip.openelse:
opener=openobj=Nonewithopener(sys.argv[1], 'rb') asinp:
obj=javaobj.load(inp, odrnavsTransformer)
pprint.pprint(obj)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions