简体   繁体   English

Mule 3.7.3-Dataveawe消息转换器编码错误

[英]Mule 3.7.3 - Dataveawe Message Transformer Encoding Wrongly

I am using mule to transform some webservice responses on my project, and currently i am using DataWeave message transformer. 我正在使用m子在项目上转换一些Web服务响应,并且当前正在使用DataWeave消息转换器。

JSON that i should transform : 我应该转换的JSON:

{
  "odata.metadata": "http://mchwtatmsdb/Across/CrossTank/api/v1/$metadata#Translations",
  "value": [
    {
      "SourceSentence": {
        "Id": 2750901,
        "Text": "Refrigerator:",
        "Language": 1033
      },
      "TargetSentence": {
        "Id": 2750902,
        "Text": "Kühlschrank:",
        "Language": 1031
      },
      "Id": 2264817,
      "Similarity": 100,
      "CreationDate": "2009-02-25T12:56:15",
      "Creator": "41e8d49d-0de7-4a96-a220-af96d94fe4b0",
      "ModificationDate": "2009-02-25T12:56:15",
      "Modificator": "00000000-0000-0000-0000-000000000000",
      "State": "SmartInserted",
      "Note": ""
    },
    {
      "SourceSentence": {
        "Id": 2750906,
        "Text": "Refrigerator*",
        "Language": 1033
      },
      "TargetSentence": {
        "Id": 2750907,
        "Text": "Kühlschrank*",
        "Language": 1031
      },
      "Id": 2264822,
      "Similarity": 100,
      "CreationDate": "2009-02-25T12:55:46",
      "Creator": "41e8d49d-0de7-4a96-a220-af96d94fe4b0",
      "ModificationDate": "2009-02-25T12:55:46",
      "Modificator": "00000000-0000-0000-0000-000000000000",
      "State": "SmartInserted",
      "Note": ""
    }
  ]
}

I am basically using transformer, define metadatas respective to json files that is included in the project. 我基本上是使用转换器,定义项目中包含的json文件所对应的元数据。

So transformer part is so simple : 所以变压器部分是如此简单:

<dw:set-payload><![CDATA[%dw 1.0
%output application/json
---
{
    "odata.metadata": payload."odata.metadata",
    value: payload.value map ((value , indexOfValue) -> {
        SourceSentence: {
            Id: value.SourceSentence.Id,
            Text: value.SourceSentence.Text as :string,
            Language: value.SourceSentence.Language
        },
        TargetSentence: {
            Id: value.TargetSentence.Id,
            Text: value.TargetSentence.Text,
            Language: value.TargetSentence.Language
        },
        Similarity: value.Similarity
    })
}]]></dw:set-payload>

Transformation runs in expected way and it gets the necessary fields that i've set in dataweave transformer, after transformer implemented on json string, it changes the encoding somehow, and output doesn't show special characters. 转换以预期的方式运行,它获得了我在dataweave转换器中设置的必要字段,在json字符串上实现了转换器之后,它以某种方式更改了编码,并且输出未显示特殊字符。 Such as: 如:

{
  "odata.metadata": "http://mchwtatmsdb/Across/CrossTank/api/v1/$metadata#Translations",
  "value": [
    {
      "SourceSentence": {
        "Id": 2750901,
        "Text": "Refrigerator:",
        "Language": 1033
      },
      "TargetSentence": {
        "Id": 2750902,
        "Text": "K252hlschrank:",
        "Language": 1031
      },
      "Similarity": 100
    },
    {
      "SourceSentence": {
        "Id": 2750906,
        "Text": "Refrigerator*",
        "Language": 1033
      },
      "TargetSentence": {
        "Id": 2750907,
        "Text": "K252hlschrank*",
        "Language": 1031
      },
      "Similarity": 100
    }
  ]
}

"Text": "K252hlschrank*" part of the string is showing "ü" character as "252" i tried to run project both on the Windows an Linux environment. 字符串的“文本”:“ K252hlschrank *”部分显示“ü”字符为“ 252”,我试图在Windows和Linux环境下都运行项目。 On linux, character is shown as "\\u00\u0026quot; so i think this is somehow related OS problem. 在Linux上,字符显示为“ \\ u00”,因此我认为这与操作系统问题有关。 I've tried several things to fix the problem. 我已经尝试了几种方法来解决此问题。

Tried to change project properties, set encoding to "UTF-8". 试图更改项目属性,将编码设置为“ UTF-8”。 It didn't work. 没用

Tried to change run configuration, set encoding to "UTF-8". 试图更改运行配置,将编码设置为“ UTF-8”。 It didn't work. 没用

Tried to give -Dfile.encoding="UTF-8" parameter into run parameters of Java, again it didn't work. 试图将-Dfile.encoding =“ UTF-8”参数提供给Java的运行参数,再次它没有用。

What is source of this problem, are transformers direclty using operating system's encoding ? 这个问题的根源是什么,使用操作系统的编码会导致变压器失真吗? Because without transformation, main json file represented as "ü", no encoding problem. 因为不进行转换,主json文件表示为“ü”,就没有编码问题。

我通过将Windows语言设置从土耳其语更改为英语(英国)来解决了这个问题……不知道它是如何实现的,但是它起到了神奇的作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM