将TreeMap扩展为在客户端上反序列化为空映射的映射

时间:2014-01-23 14:55:02

标签: gwt gwt-rpc

我需要将带有自定义字段的地图传递给客户。

只是TreeMap工作正常,但不是TreeMap的后代。如果我将TreeMap更改为HashMap,它也可以正常工作。 GWT 2.5.1

public class MyMap extends TreeMap<String, String> {

    public String s;

    public MyMap() {
    }

    public MyMap(String s) {
        this.s = s;
    }
}

public class GreetingServiceImpl extends RemoteServiceServlet implements GreetingService {
    @Override
    public Map<String, String> testSelfMap() {
        Map<String, String> c = new MyMap("abc");
        c.put("k", "v");
        return c;
    }
}

@RemoteServiceRelativePath("greet")
public interface GreetingService extends RemoteService {
    Map<String, String> testSelfMap();
}

public interface GreetingServiceAsync {
    void testSelfMap(AsyncCallback<Map<String, String>> async);
}

public class HW implements EntryPoint {
    GreetingServiceAsync serv = GWT.create(GreetingService.class);

    public void onModuleLoad() {
        serv.testSelfMap(new AsyncCallback<Map<String, String>>() {
            @Override
            public void onSuccess(Map<String, String> result) {
                System.out.println(result.get("k"));
            }
            @Override
            public void onFailure(Throwable caught) {
                caught.printStackTrace();
            }
        });
    }
}

0 个答案:

没有答案