2

我们的 Dynamics CRM 系统导出一个包含布尔元素的实体。元素可以具有的值是:true、false 和 null。如果不知道元素是否为秘密,则使用空值。例如 Dynamics 将导出以下 xml:

<SecretPhone>true</SecretPhone>
<SecretEmail>false</SecretEmail>
<SecretAddress i:nil = "true">

然后,当 BizTalk 使用带有 jsonencoder 管道的 SB 消息适配器将其发送到 Azure Servicebus 中的主题时,结果如下:

{
  "SecretPhone": true,
  "SecretEmail": false,
  "SecretAddress": ""
}

我本来希望 null 布尔值是 null 而不是空字符串:

{
  "SecretPhone": true,
  "SecretEmail": false,
  "SecretAddress": null
}

我尝试通过以下方式映射到目标 xml

<SecretAddress i:nil = "true" /> 映射到 <SecretAddress />

这导致 json 中的空字符串。(SecretAddress: "")

我也尝试像这样映射它:

<SecretAddress i:nil = "true"> 映射到 <SecretAddress i:nil = "true" />

但这会导致更奇怪的json

    "SecretAddress": {
      "@nil": "true"
    },

我们正在使用 BizTalk 2020 CU3。Sandro Pereira 构建了一个自定义的 JsonEncoder 管道组件,它可以覆盖内置的 JsonEncoder,所以也许我需要使用它。我现在的解决方法是将 null 布尔值映射为 false,但这会改变发送到目标系统的数据。

将 null xml boolean 值 jsonencode 为 null json 值的任何其他方法?

4

1 回答 1

1

由于圣诞节假期,需要一些时间,然后等待测试人员的反馈。在阅读了@Dijkgraaf 对他在上面评论中链接到的问题的回答后,我设法解决了这样的问题:

目标模式中的所有布尔元素都将 nillable 属性设置为 true。然后在 BizTalk 映射中,我使用带有内联 xslt 的脚本函数来映射布尔元素:

<xsl:variable name="boolEmail" select="/SecretEmail"/>
<xsl:choose>
    <xsl:when test="$boolEmail=''">
            <SecretEmail/>
    </xsl:when>
    <xsl:otherwise>
            <SecretEmail>
              <xsl:value-of select="$boolEmail" /> 
            </SecretEmail>
    </xsl:otherwise>
</xsl:choose>

有了这个,我现在在目标消息中得到 true、false 和 null json 值。

于 2022-01-13T12:41:58.183 回答