jezztify
jezztify

Reputation: 85

How to retain file encoding using karate.read and karate.write

I was trying to rewrite an XML file that was originally encoded as ISO-8859-1. When I tried to print the output, it was giving me garbled letters. Can someone pls help how to solve this issue?

someFile.xml (make sure file is saved in ISO-8859-1 encoding)

<?xml version="1.0" encoding="ISO-8859-1"?>
<text>å bestå gjennom fem århundrer også tålt</text>

test.feature

* def xmlData = karate.read("someFile.xml")
* karate.log(karate.prettyXml(xmlData))

Output:

<text>� best� gjennom fem �rhundrer ogs� t�lt</text>

I've made sure that my pom.xml is using ISO-8859-1 encoding

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <version>2.10</version>
  <configuration>
    <argLine>-Dfile.encoding=ISO-8859-1</argLine>
  </configuration>
</plugin>

Upvotes: 1

Views: 473

Answers (1)

Peter Thomas
Peter Thomas

Reputation: 58058

Internally Karate is biased towards UTF-8. So far this hasn't been an issue.

I suggest two options:

  • please contribute code to Karate to improve it
  • write a custom Java utility that does the read and write exactly the way you want, perhaps if you share that code once it works, we can consider making this part of the Karate "core". please refer to Java interop in the documentation.

Also see: https://stackoverflow.com/a/54593057/143475

Upvotes: 2

Related Questions