2. serialize

基本信息

  1. 接口名称: com.webank.weid.suite.api.transportation.inf.QrCodeTransportation.serialize
  2. 接口定义: <T extends JsonSerializer> ResponseData<String> serialize(T object,ProtocolProperty property)
  3. 接口描述: 用于序列化对象,要求对象实现JsonSerializer接口。

接口入参:

名称类型非空说明备注
object<T extends JsonSerializer>Y待序列化对象
propertyProtocolPropertyY协议配置

接口返回: com.webank.weid.protocol.response.ResponseData<String>;

名称类型说明备注
errorCodeInteger返回结果码
errorMessageString返回结果描述
resultString序列化后的字符串数据业务数据

此方法返回code

enumcodedesc
SUCCESS0成功
TRANSPORTATION_PROTOCOL_PROPERTY_ERROR100801协议配置异常
TRANSPORTATION_PROTOCOL_ENCODE_ERROR100803协议配置Encode异常
TRANSPORTATION_PROTOCOL_DATA_INVALID100805协议数据无效
TRANSPORTATION_ENCODE_BASE_ERROR100807Encode基本未知异常
PRESISTENCE_DATA_KEY_INVALID100901id无效
UNKNOW_ERROR160003未知异常
BASE_ERROR160007weId基础未知异常
SQL_EXECUTE_FAILED160011SQL执行异常
SQL_GET_CONNECTION_ERROR160013获取数据源连接异常

调用示例

  1. String weId = "did:weid:0x0106595955ce4713fd169bfa68e599eb99ca2e9f";
  2. List<String> verifierWeIdList = new ArrayList<String>();
  3. verifierWeIdList.add(weId);
  4.  
  5. PresentationE presentation;
  6.  
  7. //原文方式调用
  8. ResponseData<String> result1 =
  9. TransportationFactory
  10. .newQrCodeTransportation()
  11. .specify(verifierWeIdList)
  12. .serialize(presentation,new ProtocolProperty(EncodeType.ORIGINAL));
  13.  
  14. //密文方式调用
  15. ResponseData<String> result2 =
  16. TransportationFactory
  17. .newQrCodeTransportation()
  18. .specify(verifierWeIdList)
  19. .serialize(presentation,new ProtocolProperty(EncodeType.CIPHER));

时序图

sequenceDiagramparticipant 调用者participant QrCodeTransportation调用者->>QrCodeTransportation: 调用serialize()QrCodeTransportation->>QrCodeTransportation: 入参非空、格式及合法性检查opt 入参校验失败QrCodeTransportation—>>调用者: 报错,提示参数不合法并退出endQrCodeTransportation->>QrCodeTransportation: 拼装协议头数据QrCodeTransportation->>QrCodeTransportation: 判断是采用加密方式还是非加密方式opt 非加密方式QrCodeTransportation->>QrCodeTransportation: 将presentation原文放入协议里endopt 加密方式QrCodeTransportation->>EncodeProcessor: 调用encode方法EncodeProcessor->>EncodeProcessor: 采用AES算法,生成对称加密秘钥EncodeProcessor->>persistence: 保存至存储库里persistence—>>EncodeProcessor: 返回EncodeProcessor—>>QrCodeTransportation: 返回加密之后的presentation数据QrCodeTransportation->>QrCodeTransportation: 将presentation密文放入协议里endQrCodeTransportation—>>调用者: 返回QRCode协议数据