I have a customer who has a UTF-8 database and we use the HTTP plugin to post data to a third party which stores it in a Latin1 database.
Is there any way in Servoy, JavaScript or Java to transcode the UTF-8 data into Latin1 before we send it over?
I would be nice to be able to do this without needing to go to the commandline and use tools like iconv.
Just watch out for the fact that you cannot use a JavaScript String but a JAVA String if you want to use the getBytes() method! So you will probably need to create a Java String out of your JavaScript String first, with something like:
var bytes = new java.lang.String(inputString).getBytes('Latin1');
To do this in a JavaScript method from within Servoy:
//go from a JavaScript string to a byte[]
var myString = 'hello';
var myStringsByteArray = new Packages.java.lang.String(myString).getBytes()
//To go from a byte[] to a JavaScript string in default encoding
var myString = 'hello';
var myStringsByteArray = new Packages.java.lang.String(myString).getBytes()
var myString2 = new Packages.java.lang.String(myStringsByteArray);
//To go from a byte[] to a JavaScript string in a specific encoding
var myString = 'hello';
var myStringsByteArray = new Packages.java.lang.String(myString).getBytes()
var myString2 = new Packages.java.lang.String(myStringsByteArray, 'ISO-8859-1');
//See http://java.sun.com/j2se/1.3/docs/api/java/lang/package-summary.html#charenc for more info on possible encodings
//To go from a byte[] to a JavaScript string in a specific encoding
var myString = ‘hello’;
var myStringsByteArray = new Packages.java.lang.String(myString).getBytes()
var myString2 = new Packages.java.lang.String(myStringsByteArray, ‘ISO-8859-1’);
//See JDK 23 Documentation - Home for more info on possible encodings
I get the error that getBytes() is not a function.
Interestingly enough this does work on Servoy 5 (and I assume in 4.x) but doesn’t work in Servoy 3.5 (where I need to deploy it on)
All on the same machine and thus the same Java version.