@@ -28,22 +28,27 @@ This fork intends to work both on Python 2.7 and Python 3.4+.
2828| Implementations | Version |
2929| -----------------| ----------|
3030| ` v1 ` , ` v2 ` | ` 0.4.0+ ` |
31+ | ` v3 ` | ` 0.5.0+ ` |
3132
32- Since version 0.4.0, two implementations of the parser are available:
33+ Since version 0.4.0, three implementations of the parser are available:
3334
3435* ` v1 ` : the * classic* implementation of ` javaobj ` , with a work in progress
3536 implementation of a writer.
36- * ` v2 ` : the * new * implementation, which is a port of the Java project
37+ * ` v2 ` : a rewritten implementation, which is a port of the Java project
3738 [ ` jdeserialize ` ] ( https://github.com/frohoff/jdeserialize/ ) ,
3839 with support of the object transformer (with a new API) and of the ` numpy `
3940 arrays loading.
41+ * ` v3 ` : a ** new** implementation, written from scratch to benefit from
42+ Python 3.12+ features.
4043
4144You can use the ` v1 ` parser to ensure that the behaviour of your scripts
4245doesn't change and to keep the ability to write down files.
4346
44- You can use the ` v2 ` parser for new developments
45- * which won't require marshalling* and as a * fallback* if the ` v1 `
46- fails to parse a file.
47+ You can use the ` v2 ` parser for developments in Python versions lower
48+ than 3.12 and * which won't require marshalling* , or as a * fallback*
49+ if the ` v1 ` parser fails to parse a file.
50+
51+ For new development, you should use the ` v3 ` parser.
4752
4853### Object transformers V1
4954
@@ -147,8 +152,8 @@ with open("objCollections.ser", "rb") as fd:
147152
148153** Note:** The objects and methods provided by ` javaobj ` module are shortcuts
149154to the ` javaobj.v1 ` package, for Compatibility purpose.
150- It is ** recommended** to explicitly import methods and classes from the ` v1 `
151- ( or ` v2 ` ) package when writing new code, in order to be sure that your code
155+ It is ** recommended** to explicitly import methods and classes from the ` v1 ` ,
156+ ` v2 ` , or ` v3 ` package when writing new code, in order to be sure that your code
152157won't need import updates in the future.
153158
154159
@@ -404,13 +409,13 @@ class JavaRandomTransformer(BaseTransformer):
404409 values = []
405410 for f_name, f_type in zip (self .field_names, self .field_types):
406411 values.append(parser._read_field_value(f_type))
407- fields.append(javaobj.beans.JavaField(f_type, f_name))
412+ fields.append(javaobj.v2. beans.JavaField(f_type, f_name))
408413
409- class_desc = javaobj.beans.JavaClassDesc(
410- javaobj.beans.ClassDescType.NORMALCLASS
414+ class_desc = javaobj.v2. beans.JavaClassDesc(
415+ javaobj.v2. beans.ClassDescType.NORMALCLASS
411416 )
412417 class_desc.name = self .name
413- class_desc.desc_flags = javaobj.beans.ClassDataType.EXTERNAL_CONTENTS
418+ class_desc.desc_flags = javaobj.v2. beans.ClassDataType.EXTERNAL_CONTENTS
414419 class_desc.fields = fields
415420 class_desc.field_data = values
416421 return class_desc
@@ -486,7 +491,8 @@ transformers = [
486491 RandomChildTransformer(),
487492 JavaRandomTransformer()
488493]
489- pobj = javaobj.loads(" custom_objects.ser" , * transformers)
494+ with open (" custom_objects.ser" , " rb" ) as fd:
495+ pobj = javaobj.load(fd, * transformers)
490496
491497# Here we show a field that isn't visible from the class description
492498# The field belongs to the class but it's not serialized by default because
@@ -530,7 +536,7 @@ value = pobj.myField
530536| Feature | V1 | V2 | V3 |
531537| ---| ---| ---| ---|
532538| Python 3.12+ (` match/case ` , PEP 604) | ✗ | ✗ | ✓ |
533- | Fully typed (` dataclasses ` , ` TypeAlias ` ) | ✗ | partial | ✓ |
539+ | Fully typed (` dataclasses ` , PEP 695 ` type ` aliases ) | ✗ | partial | ✓ |
534540| ` TC_RESET ` handling | ✗ | ✗ | ✓ |
535541| ` TC_EXCEPTION ` in object graph | ✗ | ✗ | ✓ |
536542| ` TC_PROXYCLASSDESC ` | ✗ | ✓ | ✓ |
0 commit comments