Adds support for SC_WRITE_METHOD#38
Conversation
|
Test case:
public class App implements Serializable {
int val = 3;
Obj custom_obj = new Obj(1, 4.5);
public static void main( String[] args ) throws Exception
{
App programm = new App();
programm.start();
}
public void start() throws Exception {
FileOutputStream fileOut = new FileOutputStream("/tmp/serialized.ser");
ObjectOutputStream out = new ObjectOutputStream(fileOut);
this.writeObject(out);
out.close();
fileOut.close();
}
private void writeObject (ObjectOutputStream out) throws IOException {
out.writeObject (this.custom_obj);
out.writeInt (this.val);
}
}
class Obj implements Serializable{
int num;
double doub;
Obj(int num, double doub) {
this.num = num;
this.doub = doub;
}
private void writeObject (ObjectOutputStream out) throws IOException {
ObjectOutputStream.PutField fields = out.putFields();
fields.put("num", this.num);
fields.put("doub", this.doub);
out.writeFields();
}
}Python custom transformer: class CustomTransformer:
def __init__(self):
self.name = "topics.Obj"
self.fields = {
'doub': javaobj.beans.FieldType.DOUBLE,
'num': javaobj.beans.FieldType.INTEGER,
}
def create_instance(self, classdesc):
if classdesc.name == self.name:
# We can handle this class description
return CustomTransformer()
return None
def load_custom_writeObject(self, parser, reader, name):
if name == self.name:
return self.get_class_description(parser)
return None
def get_class_description(self, parser):
fields = []
values = []
for field_name, field_type in self.fields.items():
values.append(parser._read_field_value(field_type))
fields.append(javaobj.beans.JavaField(field_type, field_name))
class_desc = javaobj.beans.JavaClassDesc(javaobj.beans.ClassDescType.NORMALCLASS)
class_desc.name = self.name
class_desc.desc_flags = javaobj.beans.ClassDataType.EXTERNAL_CONTENTS
class_desc.fields = fields
class_desc.field_data = values
return class_desc |
|
Hi, |
|
3 tests are not working with this PR:
I'm investigating |
|
OK so the issue is that the new transformer API wasn't backported to the DefaultObjectTransformer. |
|
All test fixed |
|
OK, good for me |
|
Last thing: which names do I have to add to the |
|
Federico Alves |
|
Hi again, |
|
Hi! Yes sure, I'll make a new PR with a test implementation for a custom case. |
Changes from this PR: