Java POJO to EDI - Data bind using JavaBeans

26 views
Skip to first unread message

Mantra

unread,
Jun 28, 2024, 11:28:53 AMJun 28
to Smooks Users
Hi, Do we have any example to data bind Java POJO using Smooks JavaBean to unparse to EDI please? I can see the example for XML-to-EDI but looking for an example/suggestion to data bind JAVA (POJO's) to EDI using Javabeans (same way how we do for EDI-to-JAVA data bind)?

Claude

unread,
Jul 4, 2024, 4:11:19 AM (13 days ago) Jul 4
to Smooks Users
There is the java-to-edifact example if that counts:

UML sequence diagram

paper Singh

unread,
Jul 5, 2024, 3:28:01 AM (12 days ago) Jul 5
to smook...@googlegroups.com
Hi Claude,

Thank you for the reply. I am looking for more custom/ general implementation of Edifact. I have parsed using edi cartridges using javabeans but wanted some example for unparsing using javabeans. 

Regards

--
You received this message because you are subscribed to the Google Groups "Smooks Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to smooks-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/smooks-user/a88ac7e1-627f-40d8-9f4a-bae55f21605an%40googlegroups.com.

Claude

unread,
Jul 5, 2024, 3:37:41 AM (12 days ago) Jul 5
to Smooks Users
You mean EDI to JavaBeans to EDI?

paper Singh

unread,
Jul 5, 2024, 4:05:49 AM (12 days ago) Jul 5
to smook...@googlegroups.com
That's right.  Cheers

Claude Mamo

unread,
Jul 5, 2024, 6:30:55 AM (12 days ago) Jul 5
to smook...@googlegroups.com
Normally I would advise to use pipelines introduced in Smooks 2 together with the poorly documented core:delegate-reader (which will be called core:rewrite in the next umbrella release of Smooks) to serialise the beans to XML (e..g, using XStream) so that then you can feed the data to edi:unparser. The problem is that core:delegate-reader doesn't inherit the Smooks bean context which means that you can't reference the beans from within the pipeline to serialise them to XML. I intend to change this behaviour in the next release to support your use case. Will also add an example.

In the meantime, the best workaround I can think of is creating two Smooks instances, each with a separate config. One instance of Smooks would be used ingest the EDI and bind it to the beans while the other instance of Smooks would be used to serialise the data to EDI. When reading the result beans from the first Smooks instance, you could use something like XStream to serialise the beans to XML and then feed this XML to the second Smooks instance.

Claude

Claude Mamo

unread,
Jul 8, 2024, 2:32:01 PM (9 days ago) Jul 8
to smook...@googlegroups.com
The problem is that core:delegate-reader doesn't inherit the Smooks bean context which means that you can't reference the beans from within the pipeline to serialise them to XML.

I dived into this use case and it dawned on me that you don't need to use core:delegate-reader. A custom pipeline reader is enough so you can implement this with the latest release of Smooks. Posted an example in the smook-examples repo.

paper Singh

unread,
Jul 8, 2024, 2:36:32 PM (9 days ago) Jul 8
to smook...@googlegroups.com
Thank you Claude, I will try  using the example you provided. Thank you so much
 

paper Singh

unread,
Jul 13, 2024, 7:14:31 PM (3 days ago) Jul 13
to smook...@googlegroups.com
Hi Claude, Thank you for the example and it worked as expected. Just one warning (Bit irritating) visible on cmd regarding the XStream, Look like on Java 17 or 21 it throws a warning, This is coming from the same example running on Java21

Logs:

2024-07-13T23:33:31.155+01:00  INFO 10220 --- [nio-8080-exec-3] o.s.c.dfdl.DataProcessorFactory          : Compiling and caching DFDL schema...
2024-07-13T23:33:32.396+01:00  WARN 10220 --- [nio-8080-exec-3] o.smooks.engine.delivery.AbstractParser  : XMLReader property 'http://xml.org/sax/properties/lexical-handler' not recognized by XMLReader 'com.example.models.BeanXMLReader'.
2024-07-13T23:33:32.495+01:00  WARN 10220 --- [nio-8080-exec-3] o.smooks.engine.delivery.AbstractParser  : XMLReader property 'http://xml.org/sax/properties/lexical-handler' not recognized by XMLReader 'com. example .models.BeanXMLReader'.
2024-07-13T23:33:32.502+01:00  WARN 10220 --- [nio-8080-exec-3] o.smooks.engine.delivery.AbstractParser  : XMLReader property 'http://xml.org/sax/properties/lexical-handler' not recognized by XMLReader 'com.example .models.BeanXMLReader'.
2024-07-13T23:33:32.508+01:00  WARN 10220 --- [nio-8080-exec-3] o.smooks.engine.delivery.AbstractParser  : XMLReader property 'http://xml.org/sax/properties/lexical-handler' not recognized by XMLReader 'com.example.models.BeanXMLReader'.


Claude

unread,
4:14 AM (2 hours ago) 4:14 AM
to Smooks Users
Took a quick look at the code and I don't think it's anything to worry about unless you have lexical events like CDATA. Just configure Log4j so that it logs only info and errors for org.smooks.engine.delivery.AbstractParser.

Claude
Reply all
Reply to author
Forward
0 new messages