Hi, all.  Since the list is quiet I thought I'd run something by you.

I wrote a custom splitter that's working just fine, so I really don't need any 
help.

But I was curious if I could have done things simpler with some combination of 
split(), tokenize() and Simple, etc.?

~~~

I hit an endpoint that returns a String representing a list of lists of the 
form:

[ [ "line 1", "line 2" ], [ "line 1", "line 2" ], ... [ "line 1", "line 2" ] ]

The goal was to iterate on the inner-lists and pass each "line 1"/"line 2" pair 
to a processor.

I couldn't quite get split() to work as-is, and tried playing around a bit with 
tokenize().

Ultimately, I created the following custom splitter, which creates an array of 
strings which can be split on, and added it to my route with 
.split().method("MySplitter", "splitList").

But could I have done something simpler?

Thanks.

~~~

    /* Converts a string representing a lists of lists into an array of strings 
of the form:
       "line 1", "line 2"
       ...
       "line 1", "line 2"
    */
    public List<String> splitList (String body)
    {
        String lists = body.trim();
        lists = lists.substring(1, lists.length()-1);
        List<String> answer = new ArrayList<String>();
        for ( String list : lists.split("],") ) {
            answer.add(list.replace("[", "").replace("]", "").trim());
        }
        return answer;
    }

Reply via email to