[resolved] Convert LIST to String

Four Stars

[resolved] Convert LIST to String

Description:

My job: (Talend v5.6)


product_description field on json = ["aaa" , "bbb" , "ccc" , "dd,ee" , "ac, bd ,ef"] (***) 
Using tExtractJSONField to load (***) and check "Is Array", convert to "String, List, Object"



In tMap, I try with data type: String, List, Object ... to mapping product_description



And result after mapping =  [aaa , bbb , ccc , dd,ee , ac, bd ,ef] 

Problems:
1/ I search on google about LIST type in Talend, but can not understand .
2/ I try to make data after loading like:  
aaa 
bbb 
ccc
dd,ee 
ac, bd ,ef

Edit:
From  Talend document
--> Is Array: select this check box when the JSON field to be extracted is an array instead of an object.
But what kind of "an array" , string array  or list or array list ... 

Thanks.


Accepted Solutions
Four Stars

Re: [resolved] Convert LIST to String

I am sorry about my mistake.
Because of null value in product_description , so I got errors above. 

Here my code:


    public static String convertToString( List input) {
    String rs = "";
    try {
    for(int i = 0; i< input.size(); i++)
    {
    rs = rs + input.get(i) + "\n";
    }
} catch (Exception e) {
//System.out.println (e.getMessage());
}
return rs;
    }

View solution in original post


All Replies
Four Stars

Re: [resolved] Convert LIST to String

I write a simple routine with input = product_description ( [color=#5b5b5d][size=1][font=Verdana, Helvetica, Arial, sans-serif][aaa , bbb , ccc , dd,ee , ac, bd ,ef] [/font][/size][/color]):

    public static int convertToString( String input) {
    String[] ary = input.split(","); -- this is line 38
    return ary.length;
    }


But it gets errors:

Exception in component tMap_10
java.lang.NullPointerException
at routines.convert_type.convertToString(convert_type.java:38)
at  ......


 I am curious about this problem and trying to fix.
Four Stars

Re: [resolved] Convert LIST to String

I am sorry about my mistake.
Because of null value in product_description , so I got errors above. 

Here my code:


    public static String convertToString( List input) {
    String rs = "";
    try {
    for(int i = 0; i< input.size(); i++)
    {
    rs = rs + input.get(i) + "\n";
    }
} catch (Exception e) {
//System.out.println (e.getMessage());
}
return rs;
    }

View solution in original post

2019 GARTNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

Best Practices for Using Context Variables with Talend – Part 2

Part 2 of a series on Context Variables

Blog

Best Practices for Using Context Variables with Talend – Part 1

Learn how to do cool things with Context Variables

Blog

Migrate Data from one Database to another with one Job using the Dynamic Schema

Find out how to migrate from one database to another using the Dynamic schema

Blog