W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗值獎勵
ContractConverter
接口使您可以注冊自己的合同結(jié)構(gòu)轉(zhuǎn)換器的實現(xiàn)。以下代碼清單顯示了ContractConverter
接口:
package org.springframework.cloud.contract.spec /** * Converter to be used to convert FROM {@link File} TO {@link Contract} * and from {@link Contract} to {@code T} * * @param <T > - type to which we want to convert the contract * * @author Marcin Grzejszczak * @since 1.1.0 */ interface ContractConverter<T> extends ContractStorer<T> { /** * Should this file be accepted by the converter. Can use the file extension * to check if the conversion is possible. * * @param file - file to be considered for conversion * @return - {@code true} if the given implementation can convert the file */ boolean isAccepted(File file) /** * Converts the given {@link File} to its {@link Contract} representation * * @param file - file to convert * @return - {@link Contract} representation of the file */ Collection<Contract> convertFrom(File file) /** * Converts the given {@link Contract} to a {@link T} representation * * @param contract - the parsed contract * @return - {@link T} the type to which we do the conversion */ T convertTo(Collection<Contract> contract) }
您的實現(xiàn)必須定義啟動轉(zhuǎn)換的條件。另外,您必須定義如何在兩個方向上執(zhí)行該轉(zhuǎn)換。
創(chuàng)建實施后,必須創(chuàng)建一個
/META-INF/spring.factories
文件,在其中提供實施的完全限定名稱。
以下示例顯示了典型的spring.factories
文件:
org.springframework.cloud.contract.spec.ContractConverter=\ org.springframework.cloud.contract.verifier.converter.YamlContractConverter
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: