How to get list.list for copying a list in smooks

I'm new to fists. I ran into a problem. This is a java-java conversion. I have a list, and inside it I have an internal list with two objects. How can I make list.list display a copy in smooks?

+5
source share
1 answer

From what I can say, it smooksdoes not have a method that provides this. However, you can achieve this by sorting through the lists and extracting the contents into a new list.

You can define a function for this, for example:

    public List<Object> extractEmbeddedList(List<List<Object>> embeddedList)
    {
        List<Object> extractedList = new ArrayList<Object>();

        for (List<Object> l : embeddedList) {
            for (Object o : l) {
                extractedList.add(o);
            }
        }
        return extractedList;
    }

Here is a usage example:

    List<List<Object>> embeddedList = new ArrayList<List<Object>>();
    List<Object> someEmbeddedObjects = new ArrayList<Object>();
    List<Object> moreEmbeddedObjects = new ArrayList<Object>();
    List<Object> normalList = new ArrayList<Object>();

    someEmbeddedObjects.add("I'm a String!");
    someEmbeddedObjects.add("I'm another String!");

    moreEmbeddedObjects.add(5);
    moreEmbeddedObjects.add(6);

    embeddedList.add(someEmbeddedObjects);
    embeddedList.add(moreEmbeddedObjects);

    normalList = extractEmbeddedList(embeddedList);

    System.out.println(normalList.toString());
    //Output is: [I'm a String!, I'm another String!, 5, 6]
0
source

All Articles