Skip to content

flattenAsList #2

Closed
Closed
@aekasitt

Description

This repo helped me out a lot during my work today so here is my implementation for Object List flattening for your reference.

public static List<Map <String, Object>> flattenAsList(List<?> objects) {
    List<Map<String, Object>> rows = new ArrayList<>();
    for (int i=0; i<objects.size(); i++) { 
        rows.add(JsonFlattener.flattenAsMap(/* Object-to-Json Parsing */(objects.get(i)));
    }        
    return rows;
}

My full implementation using Ebean and FasterXml's Jackson (instead of EclipseResource Jsonvalue) is:

public static List<Map<String, Object>> flattenAsList(List<?> ebeans) throws JsonMappingException, IOException {
    List<Map<String, Objects>> rows = new ArrayList<>();
    for (int i=0; i<ebeans.size(); i++) {
        rows.add(JsonFlattener.flattenAsMap(Ebean.json().toJson(ebeans.get(i))));
    }
    return rows;
}

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions