/* Ċ Ġ* ĠCopyright Ġ 2 0 1 9 ĠDavid ĠBl anc Ċ Ġ* Ċ Ġ* ĠLicensed Ġunder Ġthe ĠApache ĠLicense , ĠVersion Ġ 2 . 0 Ġ( the Ġ" License "); Ċ Ġ* Ġyou Ġmay Ġnot Ġuse Ġthis Ġfile Ġexcept Ġin Ġcompliance Ġwith Ġthe ĠLicense . Ċ Ġ* ĠYou Ġmay Ġobtain Ġa Ġcopy Ġof Ġthe ĠLicense Ġat Ċ Ġ* Ċ Ġ* ĠĠĠĠĠ Ġhttp :// www . apache . org / licenses / LICENSE - 2 . 0 Ċ Ġ* Ċ Ġ* ĠUnless Ġrequired Ġby Ġapplicable Ġlaw Ġor Ġagreed Ġto Ġin Ġwriting , Ġsoftware Ċ Ġ* Ġdistributed Ġunder Ġthe ĠLicense Ġis Ġdistributed Ġon Ġan Ġ" AS ĠIS " ĠBASIS , Ċ Ġ* ĠWITHOUT ĠWARRANTIES ĠOR ĠCONDITIONS ĠOF ĠANY ĠKIND , Ġeither Ġexpress Ġor Ġimplied . Ċ Ġ* ĠSee Ġthe ĠLicense Ġfor Ġthe Ġspecific Ġlanguage Ġgoverning Ġpermissions Ġand Ċ Ġ* Ġlimitations Ġunder Ġthe ĠLicense . Ċ Ġ*/ Ċ Ċ package Ġfr . s peek ha . http mock er . jackson Ċ Ċ import Ġcom . fasterxml . jackson . annotation . JsonInclude Ċ import Ġcom . fasterxml . jackson . databind . ObjectMapper Ċ import Ġcom . fasterxml . jackson . module . kotlin . jackson ObjectMapper Ċ import Ġcom . fasterxml . jackson . module . kotlin . jackson Type Ref Ċ import Ġfr . s peek ha . http mock er . Mapper Ċ import Ġfr . s peek ha . http mock er . model . Header Ċ import Ġfr . s peek ha . http mock er . model . Matcher Ċ import Ġfr . s peek ha . http mock er . model . Request Descriptor Ċ import Ġfr . s peek ha . http mock er . model . Response Descriptor Ċ import Ġjava . io . InputStream Ċ import Ġjava . io . OutputStream Ċ import Ġfr . s peek ha . http mock er . jackson . Header Ġas ĠJson Header Ċ import Ġfr . s peek ha . http mock er . jackson . Matcher Ġas ĠJson Matcher Ċ import Ġfr . s peek ha . http mock er . jackson . Request Descriptor Ġas ĠJson Request Descriptor Ċ import Ġfr . s peek ha . http mock er . jackson . Response Descriptor Ġas ĠJsonResponse Descriptor Ċ Ċ /** Ċ Ġ* ĠA Ġmapper Ġusing ĠJack son Ġto Ġserialize / deserialize Ġscenarios . Ċ Ġ*/ Ċ class ĠJack son Mapper Ġ: ĠMapper Ġ{ ĊĊĠĠĠ Ġprivate Ġval Ġmapper : ĠObjectMapper Ġ= ĊĠĠĠĠĠĠĠ Ġj ack son ObjectMapper (). setDefault Property In clusion ( JsonInclude . Include . NON _ AB SENT ) ĊĊĠĠĠ Ġoverride Ġfun Ġdeserialize ( payload : ĠString ): ĠList < Matcher > Ġ= ĊĠĠĠĠĠĠĠ Ġmapper . readValue < List < Json Matcher >>( payload , Ġj ack son Type Ref < List < Json Matcher >> ()) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. map Ġ{ Ġit . to Model () Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġserialize ( matchers : ĠList < Matcher >): ĠString Ġ= ĊĠĠĠĠĠĠĠ Ġmapper . writeValue AsString ( matchers . map Ġ{ Ġit . from Model () Ġ}) ĊĊĠĠĠ Ġoverride Ġfun Ġread Matches ( stream : ĠInputStream ): ĠList < Matcher > Ġ= ĊĠĠĠĠĠĠĠ Ġmapper . readValue < List < Json Matcher >>( stream , Ġj ack son Type Ref < List < Json Matcher >> ()) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. map Ġ{ Ġit . to Model () Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġwrite Value ( output Stream : ĠOutputStream , Ġmatch ers : ĠList < Matcher >) Ġ= ĊĠĠĠĠĠĠĠ Ġmapper . writeValue ( output Stream , Ġmatch ers . map Ġ{ Ġit . from Model () Ġ}) Ċ } Ċ Ċ private Ġfun ĠMatcher . from Model () Ġ= ĠJson Matcher ( request . from Model (), Ġresponse . from Model ()) Ċ Ċ private Ġfun ĠJson Matcher . to Model () Ġ= ĠMatcher ( request . to Model (), Ġresponse . to Model ()) Ċ Ċ private Ġfun ĠJson Request Descriptor . to Model () Ġ= ĊĠĠĠ ĠRequest Descriptor ( exact Match Ġ?: Ġfalse , Ġprotocol , Ġmethod , Ġhost , Ġport , Ġpath , Ġheaders . map Ġ{ Ġit . to Model () Ġ}, Ġparams , Ġbody ) Ċ Ċ private Ġfun ĠRequest Descriptor . from Model () Ġ= ĊĠĠĠ ĠJson Request Descriptor ( exact Match . take If Ġ{ Ġit Ġ}, Ġprotocol , Ġmethod , Ġhost , Ġport , Ġpath , Ġheaders . map Ġ{ Ġit . from Model () Ġ}, Ġparams , Ġbody ) Ċ Ċ private Ġfun ĠJson Header . to Model () Ġ= ĠHeader ( name , Ġvalue ) Ċ Ċ private Ġfun ĠHeader . from Model () Ġ= ĠJson Header ( name , Ġvalue ) Ċ Ċ private Ġfun ĠJsonResponse Descriptor . to Model () Ġ= ĊĠĠĠ ĠResponse Descriptor ( delay , Ġcode , Ġmedia Type , Ġheaders . map Ġ{ Ġit . to Model () Ġ}, Ġbody , Ġbody File ) Ċ Ċ private Ġfun ĠResponse Descriptor . from Model () Ġ= ĊĠĠĠ ĠJsonResponse Descriptor ( delay , Ġcode , Ġmedia Type , Ġheaders . map Ġ{ Ġit . from Model () Ġ}, Ġbody , Ġbody File ) Ċ