有一串[DataPermissionSchemaEo(id=null, databaseCode=platform, schemaCode=user_info, description=null, createProgram=null, createUser=null, createDatetime=null, modifyProgram=null, modifyUser=null, modifyDatetime=null, schemaColumnRuleEoList=[], schemaRowRuleEoList=[SchemaRowRuleEo(id=1f31b45b-c0d7-4b65-ac79-08e79517ab11, schemaId=1f31b45b-c0d7-4b65-ac79-08e79517ab82, rowRuleCode=test code 2, rowRuleDesc=行规则测试2, rowPermissionUserList=["Lebron.jie","dashuaige"], rowPermissionOrgList=null, rowReadPermission=true, rowEditPermission=true, rowDeletePermission=true, filterConditionList=null, createUser=null, createProgram=null, createDatetime=null, modifyUser=null, modifyProgram=null, modifyDatetime=null)])]是object怎么转换成目标List
时间: 2024-02-03 21:14:05 浏览: 55
可以使用Java中的Stream流进行转换。
首先,需要将这个object强制转换成List类型,然后再通过Stream流进行转换。
假设这个object的名称是dataPermissionSchemaEoList,代码示例如下:
```java
List<DataPermissionSchemaEo> list = (List<DataPermissionSchemaEo>) dataPermissionSchemaEoList;
List<SchemaRowRuleEo> result = list.stream()
.flatMap(schema -> schema.getSchemaRowRuleEoList().stream())
.collect(Collectors.toList());
```
首先将object强制转换成List<DataPermissionSchemaEo>类型,然后通过flatMap操作将每个DataPermissionSchemaEo对象中的SchemaRowRuleEo列表打平成一个新的流,最后通过collect操作将所有的SchemaRowRuleEo对象收集到一个List中。
相关问题
[DataPermissionSchemaEo(id=null, databaseCode=platform, schemaCode=user_info, description=null, createProgram=null, createUser=null, createDatetime=null, modifyProgram=null, modifyUser=null, modifyDatetime=null, schemaColumnRuleEoList=[], schemaRowRuleEoList=[SchemaRowRuleEo(id=1f31b45b-c0d7-4b65-ac79-08e79517ab11, schemaId=1f31b45b-c0d7-4b65-ac79-08e79517ab82, rowRuleCode=test code 2, rowRuleDesc=行规则测试2, rowPermissionUserList=["Lebron.jie","dashuaige"], rowPermissionOrgList=null, rowReadPermission=true, rowEditPermission=true, rowDeletePermission=true, filterConditionList=null, createUser=null, createProgram=null, createDatetime=null, modifyUser=null, modifyProgram=null, modifyDatetime=null)])]转换成list
可以使用Java代码将该对象转换为List:
```
List<DataPermissionSchemaEo> schemaEoList = new ArrayList<>();
schemaEoList.add(new DataPermissionSchemaEo(null, "platform", "user_info", null, null, null, null, null, null, null, new ArrayList<>(), Arrays.asList(new SchemaRowRuleEo(UUID.fromString("1f31b45b-c0d7-4b65-ac79-08e79517ab11"), UUID.fromString("1f31b45b-c0d7-4b65-ac79-08e79517ab82"), "test code 2", "行规则测试2", Arrays.asList("Lebron.jie", "dashuaige"), null, true, true, true, null, null, null, null)))));
```
这里将该对象封装到一个List中,List中只有一个元素。注意需要导入java.util包。
阅读全文