You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Liferay服务部署报错:返回类型为List<List<Object>>的方法触发PARSER_ERROR

Fixing PARSER_ERROR for 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).

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.

  1. 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;
        }
    }
    
  2. Update your service.xml to 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>
    
  3. Adjust your implementation method to return List<DonutChartDataItem> instead of List<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:

  1. Update service.xml:

    <method name="getDonutChartData">
        <return-type>java.util.List</return-type>
    </method>
    
  2. 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.13 09:10:26