将HashMap从Corda Flow返回到SpringBoot引发:com.esotericsoftware.kryo.KryoException

时间:2018-10-05 09:37:48

标签: java spring-boot corda

我正在使用从FLow获取数据的服务。call()的返回类型是HashMap。调用APi后,我得到了以下异常。我读到HashMap没有包括在白名单中。有人可以建议如何将Corda流中的Map或ConcurrentHashMap返回到服务。

  

“ com.esotericsoftware.kryo.KryoException:类java.util.HashMap是   没有注释或不在白名单上,因此无法在   序列化\ n序列化跟踪:\ 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();
}

1 个答案:

答案 0 :(得分:1)

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