简体   繁体   中英

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.

JSON that i should transform :

{
  "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.

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. 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. On linux, character is shown as "\\u00\u0026quot; so i think this is somehow related OS problem. I've tried several things to fix the problem.

Tried to change project properties, set encoding to "UTF-8". It didn't work.

Tried to change run configuration, set encoding to "UTF-8". It didn't work.

Tried to give -Dfile.encoding="UTF-8" parameter into run parameters of Java, again it didn't work.

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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