从corda返回HashMap Flow到SpringBoot抛出:com.esotericsoftware.kryo.KryoException

问题描述 投票:0回答:1

我正在使用从FLow获取数据的服务。调用()的返回类型是HashMap。在调用APi时,我得到以下异常。我读到HashMap没有包含在白名单中。任何人都建议如何将一个Map或ConcurrentHashMap从corda流返回到服务。

“com.esotericsoftware.kryo.KryoException:类java.util.HashMap未注释或在白名单上,因此不能用于序列化\ nSerialization trace:\ nvalue(rx.Notification)”,

一些代码片段:

    @Suspendable
    @Override
    public Map<Party, StateAndRef<MembershipState>> call() throws FlowException {

        MembershipsCacheHolder membershipService = getServiceHub().cordaService(MembershipsCacheHolder.class);

        MembershipsCache cache = membershipService.getCache();

        Instant now = getServiceHub().getClock().instant();
        System.out.println("==========started the Get membership flow " + forceRefresh + "cahce" + cache);
        if (forceRefresh || cache == null || cache.getExpires() == null || cache.getExpires().isBefore(now)) {
            MemberConfigurationService configuration = getServiceHub().cordaService(MemberConfigurationService.class);
            Party bno = configuration.bnoParty();
            FlowSession bnoSession = initiateFlow(bno);

            UntrustworthyData<MembershipsListResponse> packet2 = bnoSession.sendAndReceive(MembershipsListResponse.class, new MembershipListRequest());
            MembershipsListResponse response = packet2.unwrap(data -> {
                // Perform checking on the object received.
                // T O D O: Check the received object.
                // Return the object.
                return data;
            });
            try {
                MembershipsCache newCache = MembershipsCache.from(response);
                membershipService.setCache(newCache);
            } catch (Exception e) {
                System.out.println("==========failed the Get membership flow " + forceRefresh + "cahce" + cache);

                e.printStackTrace();
            }


            Map<Party, StateAndRef<MembershipState>> hashMap = new HashMap<Party, StateAndRef<MembershipState>>(membershipService.getCache().getMembershipMap());

            return hashMap;


        } else {

            Map<Party, StateAndRef<MembershipState>> hashMap = new HashMap<Party, StateAndRef<MembershipState>>(cache.getMembershipMap());


            return hashMap;

        }


    }


}

}

来自Spring Boot Side的AND代码:

@GetMapping(value = "getMemberShips", produces = MediaType.APPLICATION_JSON_VALUE)
public String getMembership() throws InterruptedException,JsonProcessingException , ExecutionException{

    FlowProgressHandle<Map<Party, StateAndRef<MembershipState>> > flowHandle = proxy.startTrackedFlowDynamic(GetMembershipsFlow.GetMembershipsFlowInitiator.class,true);
    flowHandle.getProgress().subscribe(evt -> System.out.printf(">> %s\n", evt));

    final Map<Party, StateAndRef<MembershipState>>  result = flowHandle
            .getReturnValue()
            .get();

    return result.toString();
}
java spring-boot corda
1个回答
1
投票

正如corda所建议的那样,我们可以使用LinkedHashMap。它工作正常。谢谢

© www.soinside.com 2019 - 2024. All rights reserved.