The new YamlSerializer... how can I use it when saving objectState?

45 views
Skip to first unread message

Howie T

unread,
Feb 28, 2017, 5:25:47 AM2/28/17
to COPPER Engine
Hi all,

I just noticed 4.2 was released :) since normally you guys will announce in the forum, but not this time.
Anyways, are we able to use YamlSerializer to save the workflow instance state and workflow data, such that the content in database is more human readable for debugging purpose... I wonder if it's possible? And how it is done?

Thank you!


Theo Diefenthal

unread,
Feb 28, 2017, 5:50:27 AM2/28/17
to copper...@googlegroups.com

Hi,

The YAML serializer is implemented only for usage with the workflow data object. You can use it simply by setting the serializer for your DB storage like so:

sqlDialect.setSerializer(new YamlSerializer());
where sqlDialect could be something like a PostgreSQLDialect. I think, it is handy to have my data in a human readable format but I don't need this for the serialization of the workflow object itself. (That is, serialization of workflow and of workflow-data are distinguished in SerializedWorkflow POJO). If you want the workflow object to be serialized by YAML as well, you should write your own Serializer class (or extend StandardJavaSerializer if you want Responses to be still serialized with that) and just override the  public SerializedWorkflow serializeWorkflow(Workflow<?> o) throws Exception as well as accordingly the derserializeWorkflow method. The implementation of these methods should be straight forward as a mix out of the original methods in StandardJavaSerializer [Create SerializeWorkflow, call setter of it and return) and the methods from the YamlSerializer. (Create the serialization string). Remember that the SerializedWorkflow class is just a POJO holding two data strings which are then stored to the database.. Best regards
-- You received this message because you are subscribed to the Google Groups "COPPER Engine" group. To unsubscribe from this group and stop receiving emails from it, send an email to copper-engin...@googlegroups.com. To post to this group, send email to copper...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/copper-engine/7d49fd9d-1378-4f6a-ab83-aead69cd8dc1%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
-- 
SCOOP Software GmbH - Gut Maarhausen - Eiler Straße 3 P - D-51107 Köln
Theo Diefenthal

T +49 221 801916-196 - F +49 221 801916-17
theo.di...@scoop-software.de - www.scoop-software.de
Sitz der Gesellschaft: Köln, Handelsregister: Köln,
Handelsregisternummer: HRB 36625
Geschäftsführung: Dr. Oleg Balovnev, Frank Heinen,
Dr. Wolfgang Reddig, Roland Scheel

Howie T

unread,
Feb 28, 2017, 6:09:03 AM2/28/17
to COPPER Engine
Thank you for the info Theo, I will give it a try!

Howie T

unread,
Feb 28, 2017, 8:47:14 AM2/28/17
to COPPER Engine
It turns out the SnakeYaml library have problem serialize enum types in the Data, they become null. This is kinda dangerous... 

Michael Austermann

unread,
Mar 1, 2017, 2:06:40 AM3/1/17
to copper...@googlegroups.com
You are right - this is ugly and dangerous.
I opened an issue for this:

Thanks for reporting...


Von: "Howie" <cka...@gmail.com>
An: "COPPER Engine" <copper...@googlegroups.com>
Gesendet: Dienstag, 28. Februar 2017 14:47:14
Betreff: Re: [COPPER Users] The new YamlSerializer... how can I use it when saving objectState?

Theo Diefenthal

unread,
Mar 2, 2017, 9:08:51 AM3/2/17
to copper...@googlegroups.com

Hi Howie,

I tried to reproduce your issue but for me, it seems to work just fine with enums. Can you give me a working example of the problem?

You can check my response to the created issue and see how I failed in reproduction:

https://github.com/copper-engine/copper-engine/issues/75

Best regards

Theo


For more options, visit https://groups.google.com/d/optout.

Howie T

unread,
Mar 5, 2017, 1:17:08 AM3/5/17
to COPPER Engine
Hi Theo & Michael,

It turns out the problem is my enum types are defined as "final" so it don't have setter on my class? So for a serializer using reflection it will not work...
Java Serialization won't have such a problem though, I guess this is something the user should know.

Cheers,

Howie


On Thursday, 2 March 2017 22:08:51 UTC+8, Theo Diefenthal wrote:

Hi Howie,

I tried to reproduce your issue but for me, it seems to work just fine with enums. Can you give me a working example of the problem?

You can check my response to the created issue and see how I failed in reproduction:

https://github.com/copper-engine/copper-engine/issues/75

Best regards

Theo



Am 01.03.2017 um 08:06 schrieb Michael Austermann:
You are right - this is ugly and dangerous.
I opened an issue for this:

Thanks for reporting...


Von: "Howie" <ck...@gmail.com>
Message has been deleted

Howie T

unread,
Mar 5, 2017, 1:58:01 AM3/5/17
to COPPER Engine
So It's actually caused by "final" fields inside my Data class, not related to enum, and some confusing after the serialized string was generated, so this is what happened:

public class TestData
{
   
private int aNumber;
   
private final int finalNumber = 42; //this also won't show up
   
private final TimeUnit timeUnit = TimeUnit.SECONDS; //or put in default constructor
   
private String someString;


...setters & getters
}


 
public static void main(String[] args) throws Exception {
       
TestData data = new TestData();
        data
.setaNumber(1111);
        data
.setSomeString("aaaaa");


       
Yaml yaml = new Yaml();
       
String s = yaml.dump(data);
       
System.out.println(s);
}


output: **"!!com.test.TestData {aNumber: 1111, someString: aaaaa}"**

This doesn't matter, because it's final anyways.... and always accessible via getter, it just won't contain in the string dump, which got me confused


But if a class doesn't have a default constructor it will cause some problem when deserializing: 

public class TestData
{
   
private int aNumber;
   
private final TimeUnit timeUnit ;
   
private String someString;


   
public TestData(TimeUnit timeUnit)
   
{
       
this.timeUnit = timeUnit;
   
}
...setters & getters
}
       
TestData data = new TestData(TimeUnit.SECONDS);
        data
.setaNumber(1111);
        data
.setSomeString("aaaaa");


       
Yaml yaml = new Yaml();
       
String s = yaml.dump(data);
       
System.out.println(s);


       
TestData data2 = (TestData) yaml.load(s);  ->  Caused by: org.yaml.snakeyaml.error.YAMLException: java.lang.NoSuchMethodException: com.test.TestData.<init>()



Michael Austermann

unread,
Mar 7, 2017, 4:28:20 AM3/7/17
to copper...@googlegroups.com
Thanks for sharing this information, Howie.

I will probably just add a warning to the javadoc of the YamlSerializer.

/Michael



Von: "Howie" <cka...@gmail.com>
An: "COPPER Engine" <copper...@googlegroups.com>
Gesendet: Sonntag, 5. März 2017 07:58:01

Betreff: Re: [COPPER Users] The new YamlSerializer... how can I use it when saving objectState?
--
You received this message because you are subscribed to the Google Groups "COPPER Engine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to copper-engin...@googlegroups.com.
To post to this group, send email to copper...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages