package com.ri;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.apache.commons.lang3.ArrayUtils;
import org.checkerframework.checker.units.qual.m;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.google.common.collect.ImmutableMap;
public class Tre {
public static void main(String[] args) {
String jsonStr = "[{\"parentID\":0,\"id\":1,\"name\": \"商品一级菜单\",\"type\": \"商品\",\"code\": \"0001\",\"childMenu\":[{\"parentID\":1,\"id\":2,\"name\": \"商品二级菜单\",\"type\": \"商品\",\"code\": \"0001\",\"childMenu\":[{\"parentID\":2,\"id\":3,\"name\": \"商品三级菜单\",\"type\": \"商品\",\"code\": \"0001\",\"childMenu\":[]}]}]}]";
List<MenuItem> menuItems = JSON.parseArray(jsonStr, MenuItem.class);
List<MenuItem> flatMenuList = new ArrayList<>();
flattenMenu(menuItems, flatMenuList);
for (MenuItem item : flatMenuList) {
System.out.println(item);