csvunixbcp

On Unix server: unable to parse currency symbol(£,€) from json to .csv file


Below is my java code

public Test parseTest(String test) {
            Testresult = null;
            try {
                result = gson.fromJson(test, Test.class);
                if (CAT.isDebugEnabled()) {
                    CAT.debug(result);
                }
            } catch (JsonSyntaxException e) {
                CAT.warn(e.getMessage() + "\nCan't parse\n" + test);
            }
            return result;
        }

To parse Json I am using below jar

<dependency>
                <groupId>com.google.code.gson</groupId>
                <artifactId>gson</artifactId>
                <version>2.2.2</version>
            </dependency>

Below is my JSON:

Test": [
      {
        "A": "X;DOS533",
        "B": "MCA TEST EUR221.5BN2199AR2019",
        "C": null,
        "D": "AA BB US1.5N",
        "E": "€1.5M Test LN BNK €100M 12M",
        "Ccy": "EUR",
        "TypeCode": "HML  "
      }

And below is the row from .csv file generated in unix box.

4243842|Test:ABC|Active||6||FFTYIAIT||Internal|X;DOAS5KT|FCA Test EUR221.5BN2199AR2019|?1.51N Test LN RTM ?100M 12M|TCL|

Here € sign get replace with ?(question mark).

Same issue I face while converting pound (£) from .csv to .bcp file.


Solution

  • I tried passing streams of bytes instead of String and it works.

    Below is the updated code

    public Test parseTest(String test) {
                Testresult = null;
                try {
                   result = gson.fromJson(new InputStreamReader(new ByteArrayInputStream(test.getBytes("UTF-8"))), Test.class);
                    if (CAT.isDebugEnabled()) {
                        CAT.debug(result);
                    }
                } catch (JsonSyntaxException e) {
                    CAT.warn(e.getMessage() + "\nCan't parse\n" + test);
                }catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
                return result;
            }