Can't get <?TEMPLATE-SPLIT-PI?> to work with Freemarker

49 visualizzazioni
Passa al primo messaggio da leggere

Gil Perry

da leggere,
7 giu 2021, 09:20:0407/06/21
a Smooks Users
Hi,

I am using version 2.0.0-M3 of Smooks and am attempting to transform Json to XML using  Freemarker with the <?TEMPLATE-SPLIT-PI?> processing instruction. However, I receive the error message:

org.smooks.api.SmooksException: Failed to filter source

I have attached a simple project with the test testJsonToXml. Any advise would be appreciated. Thanks.

The example input message is

{
  "orderId": 34567,
  "customerId": "A56787",
  "orderTotal": 13.56,
  "lineItems": [
    {
      "sku": "56789",
      "price": 1.57
    },
    {
      "sku": "4433",
      "price": 11.57
    }
  ]
}

The output should roughly be as follows:

<customer_order id="34567">
<customer_id>A56787</customer_id>
<total>13.56</total>
<line_item sku="56789">
<price>1.57</price>
</line_item>
<line_item sku="4433">
<price>11.57</price>
</line_item>
</customer_order>
smooks-json-to-xml-using-freemarker.zip

Claude Mamo

da leggere,
7 giu 2021, 14:21:2907/06/21
a smook...@googlegroups.com
Hi Gil! You've uncovered a regression in the <?TEMPLATE-SPLIT-PI?> instruction. Must have happened in the latest milestone release. It would be great if an issue about this is opened in the Templating cartridge repo. I'm unsure whether the TEMPLATE-SPLIT-PI instruction has become redundant with the introduction of pipelines however, in your particular case, you can rewrite the config to:
    <core:smooks filterSourceOn="customer_order" maxNodeDepth="0" >
<core:action>
<core:inline>
<core:replace/>
</core:inline>
</core:action>
<core:config>
<smooks-resource-list>
<ftl:freemarker applyOnElement="customer_order">
<ftl:template><!-- <customer_order id="${customer_order.orderId}">
<customer_id>${customer_order.customerId}</customer_id>
<total>${customer_order.orderTotal}</total>
<#list customer_order.lineItems.lineItem as lineItem>
<line_item sku="${lineItem.sku}">
<price>${lineItem.price}</price>
</line_item>
</#list>
</customer_order>
-->
</ftl:template>
</ftl:freemarker>
</smooks-resource-list>
</core:config>
</core:smooks>
I noticed that your project's POM is declaring each Smooks dependency's version. It's easier to manage Smooks dependencies by importing Smook's BOM and omitting the dependency versions. At the moment, the cartridge versions match the core's version but there's no guarantee that it will be always like this.

Claude

--
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/94b3bc39-60ea-4306-a5fe-d047b7993013n%40googlegroups.com.

Gil Perry

da leggere,
8 giu 2021, 04:39:3908/06/21
a smook...@googlegroups.com
Thanks for responding so quickly Claude. That's really helpful info. 


You received this message because you are subscribed to a topic in the Google Groups "Smooks Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/smooks-user/4EuvRYWvUX8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to smooks-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/smooks-user/CADvAAuj-e5HYqHcgXi6E4RDn4o3d46AVrGk6VdoSFGjet8MrSQ%40mail.gmail.com.
Rispondi a tutti
Rispondi all'autore
Inoltra
0 nuovi messaggi