Liferay服务部署报错:返回类型为List<List<Object>>的方法触发PARSER_ERROR
List<List<Object>> Return Type in Liferay 6.2-EE-SP17 ServiceBuilder I’ve run into this exact headache with Liferay 6.2’s ServiceBuilder before—its old ANTLR-based parser just doesn’t play nice with nested generics like List<List<Object>>. Let’s break down how to fix this:
Root Cause
Liferay 6.2’s ServiceBuilder parser has limited support for nested generic type syntax. When it sees List<List<Object>>, it misinterprets the nested angle brackets as invalid code, triggering the PARSER_ERROR you’re seeing (expecting a semicolon or end-of-file instead of your method name/return keyword).
Solution 1: Use a Wrapper Class (Recommended)
The cleanest, type-safe fix is to wrap the inner List<Object> in a simple serializable class, then use that wrapper as the type in your outer list. This avoids nested generics entirely, which ServiceBuilder can parse correctly.
Create a serializable wrapper class in your project:
package com.yourcompany.yourproject.model; import java.io.Serializable; import java.util.List; public class DonutChartDataItem implements Serializable { private List<Object> dataPoints; // Getters and Setters public List<Object> getDataPoints() { return dataPoints; } public void setDataPoints(List<Object> dataPoints) { this.dataPoints = dataPoints; } }Update your
service.xmlto use this wrapper class as the return type:<entity name="YourEntity" local-service="true" remote-service="false"> <!-- Existing entity configuration --> <method name="getDonutChartData"> <return-type>java.util.List<com.yourcompany.yourproject.model.DonutChartDataItem></return-type> </method> </entity>Adjust your implementation method to return
List<DonutChartDataItem>instead ofList<List<Object>>:@Override public List<DonutChartDataItem> getDonutChartData() { List<DonutChartDataItem> result = new ArrayList<>(); // Populate your data into DonutChartDataItem instances List<Object> innerData = Arrays.asList("Sample Label", 45); DonutChartDataItem item = new DonutChartDataItem(); item.setDataPoints(innerData); result.add(item); return result; }
Solution 2: Use Raw List (Quick, Not Type-Safe)
If you need a temporary workaround and don’t mind losing type safety, you can use a raw List as the return type in service.xml, then cast it in your implementation:
Update
service.xml:<method name="getDonutChartData"> <return-type>java.util.List</return-type> </method>Cast in your implementation:
@Override public List getDonutChartData() { List<List<Object>> data = // your existing data logic return data; }Note: This will generate unchecked cast warnings, so it’s only recommended for short-term fixes.
Verification
After making your changes, re-run the ServiceBuilder task:
ant build-service
This should regenerate the service layer code without the parser error. Double-check the generated ServiceBuilder.temp file to confirm the method is parsed correctly.
内容的提问来源于stack exchange,提问作者kirti

