Title: Custom transformer - create_instance invoked incorrectly? · Issue #54 · tcalmant/python-javaobj · GitHub
Open Graph Title: Custom transformer - create_instance invoked incorrectly? · Issue #54 · tcalmant/python-javaobj
X Title: Custom transformer - create_instance invoked incorrectly? · Issue #54 · tcalmant/python-javaobj
Description: 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 "/ho...
Open Graph Description: 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 t...
X Description: 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) f...
Opengraph URL: https://github.com/tcalmant/python-javaobj/issues/54
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Custom transformer - create_instance invoked incorrectly?","articleBody":"Hello!\r\n\r\nI'm trying to parse a file serializing an `ArrayList` of custom functions -- and I cannot even get the basics going...\r\n\r\nBelow is my entire script. Without the default value (such as `None`) for the `class_desc`, I get an error:\r\n```\r\n File \"/home/mi/.local/lib/python3.9/site-packages/javaobj/v2/core.py\", line 528, in _do_object\r\n instance = self._create_instance(class_desc)\r\n File \"/home/mi/.local/lib/python3.9/site-packages/javaobj/v2/core.py\", line 503, in _create_instance\r\n instance = transformer.create_instance(class_desc)\r\nTypeError: create_instance() missing 1 required positional argument: 'class_desc'\r\n```\r\n\r\nIf 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:\r\n```\r\nINFO:javaobj.parser:Reading next content\r\nDEBUG:javaobj.parser:Reading new object: handle 7e0001, classdesc [classdesc 0x7e0000: name java.util.ArrayList, uid 8683452581122892189]\r\nSelf is [classdesc 0x7e0000: name java.util.ArrayList, uid 8683452581122892189], class_desc is None\r\nTraceback ...\r\n```\r\n\r\nPlease, advise. Thank you!\r\n\r\n```python\r\nimport javaobj.v2 as javaobj\r\nimport sys\r\nimport os\r\nimport json\r\nimport pprint\r\nimport logging\r\n\r\nlogging.basicConfig(level = logging.DEBUG)\r\n\r\nclass odrnavsFunctionInstance(javaobj.beans.JavaInstance):\r\n\tdef __init__(self):\r\n\t\tjavaobj.beans.JavaInstance.__init__(self)\r\n\r\n\tdef load_from_instance(self):\r\n\t\tif not self.classdesc or self.classdesc not in self.field_data:\r\n\t\t\treturn False\r\n\r\n\t\tfields = self.classdesc.fields_names\r\n\t\tvalues = [\r\n\t\t\tself.field_data[self.classdesc][self.classdesc.fields[i]]\r\n\t\t\tfor i in range(len(fields))\r\n\t\t]\r\n\t\tself.field_data = dict(zip(fields, values))\r\n\t\tif not self.classdesc.super_class or \\\r\n\t\t self.classdesc.super_class not in self.annotations:\r\n\t\t\treturn True\r\n\t\tsuper_class = self.annotations[self.classdesc.super_class][0]\r\n\t\tself.annotations = dict(zip(super_class.fields_names, super_class.field_data))\r\n\t\treturn True\r\n\r\nclass odrnavsTransformer(javaobj.transformers.ObjectTransformer):\r\n\r\n\tdef __init__(self, handled_classes = {\r\n\t\t'my.apps.datalayer.client.navs.shared.api.Function':\r\n\t\t odrnavsFunctionInstance\r\n\t}):\r\n\t\tsuper(JavaRandomTransformer, self).__init__()\r\n\t\tself.instance = None\r\n\t\tself.handled_classes = handled_classes or {}\r\n\r\n\tdef create_instance(self, class_desc = None):\r\n\t\tprint('Self is %s, class_desc is %s' % (self, class_desc))\r\n\t\tif class_desc.name not in self.handled_classes:\r\n\t\t\treturn None\r\n\t\tself.instance = self.handled_classes[class_desc.name]()\r\n\t\treturn self.instance\r\n\r\nif sys.argv[1].endswith('.gz'):\r\n\timport gzip\r\n\topener = gzip.open\r\nelse:\r\n\topener = open\r\n\r\nobj = None\r\nwith opener(sys.argv[1], 'rb') as inp:\r\n\t\tobj = javaobj.load(inp, odrnavsTransformer)\r\n\r\npprint.pprint(obj)\r\n```\r\n","author":{"url":"https://github.com/UnitedMarsupials","@type":"Person","name":"UnitedMarsupials"},"datePublished":"2023-08-02T23:40:15.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/54/python-javaobj/issues/54"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:357c040c-ffb7-fcf6-8cad-ee4e297ed272 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 98C6:21FEDA:51D829:724157:696A78AF |
| html-safe-nonce | 5aaac845199d837c94f0fe4bf7ba4b32e461b47482757cb227cef6b0f907b891 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5OEM2OjIxRkVEQTo1MUQ4Mjk6NzI0MTU3OjY5NkE3OEFGIiwidmlzaXRvcl9pZCI6IjY5NzUwODc3MjAwOTQzOTg2MzkiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | e2e78cfa926a61aa4fe658bf47a28b20cb3b20eee5cdefe325527c2525a485c3 |
| hovercard-subject-tag | issue:1834028583 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/tcalmant/python-javaobj/54/issue_layout |
| twitter:image | https://opengraph.githubassets.com/239a87eb80a8b968ea0e0b58d8b38353f19abf804414074e815e0d634424c196/tcalmant/python-javaobj/issues/54 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/239a87eb80a8b968ea0e0b58d8b38353f19abf804414074e815e0d634424c196/tcalmant/python-javaobj/issues/54 |
| og:image:alt | 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 t... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | UnitedMarsupials |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5b774e44f85c14a75886edd04ddda4e5a25ddebbb241bcbb590b08a3048730e8 |
| turbo-cache-control | no-preview |
| go-import | github.com/tcalmant/python-javaobj git https://github.com/tcalmant/python-javaobj.git |
| octolytics-dimension-user_id | 1540582 |
| octolytics-dimension-user_login | tcalmant |
| octolytics-dimension-repository_id | 15333794 |
| octolytics-dimension-repository_nwo | tcalmant/python-javaobj |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 15333794 |
| octolytics-dimension-repository_network_root_nwo | tcalmant/python-javaobj |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | cc5f4eee261b3601c1e98e217ceaf28508b9567e |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width