package Ġnorth . under tow . example . filters Ċ Ċ import Ġcom . fasterxml . jackson . databind . ObjectMapper Ċ import Ġio . under tow . server . HttpServer Exchange Ċ import Ġio . under tow . util . Attachment Key Ċ import Ġio . under tow . util . Headers Ċ import Ġio . under tow . util . StatusCode s Ċ import Ġnorth . under tow . Response Filter Ċ Ċ object ĠMarshal ing Filter Ġ{ ĊĠĠĠ Ġfun Ġfilter ( object Mapper : ĠObjectMapper ): ĠResponse Filter Ġ= Ġ{ Ġexchange Ġ-> ĊĠĠĠĠĠĠĠ Ġval Ġresponse Object Ġ= Ġexchange . get Attachment ( RESPONSE _ OBJECT _ KEY ) ĊĠĠĠĠĠĠĠ Ġif Ġ( response Object Ġ!= Ġnull ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval ĠcontentType Ġ= Ġwhen Ġ( response Object . value ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġis ĠProblem Ġ-> Ġ" application / problem + json " ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġelse Ġ-> Ġ" application / json " ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġexchange . statusCode Ġ= Ġresponse Object . statusCode ĊĠĠĠĠĠĠĠĠĠĠĠ Ġexchange . response Headers . add ( Headers . CONTENT _ TYPE , ĠcontentType ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġexchange . response Sender . send ( object Mapper . writeValue AsString ( response Object . value )) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġval ĠRESP ONSE _ OBJECT _ KEY Ġ= ĠAttachment Key . create ( Response Object :: class . java ) !! Ċ } Ċ Ċ data Ġclass ĠResponse Object ( val ĠstatusCode : ĠInt , Ġval Ġvalue : ĠAny ) Ċ Ċ data Ġclass ĠProblem ( val Ġstatus : ĠInt , Ġval Ġtitle : ĠString , Ġval Ġdetail : ĠString Ġ= Ġ"") Ġ{ ĊĠĠĠ Ġcompanion Ġobject Ġ{ ĊĠĠĠĠĠĠĠ Ġval ĠU NA UTH ORIZ ED Ġ= ĠProblem ( StatusCode s . UN AUTHORIZ ED , ĠStatus Codes . UN AUTHORIZ ED _ STRING ) ĊĠĠĠĠĠĠĠ Ġval ĠFOR BID DEN Ġ= ĠProblem ( StatusCode s . FOR BID DEN , ĠStatus Codes . FOR BID DEN _ STRING ) ĊĠĠĠĠĠĠĠ Ġval ĠCON FLI CT Ġ= ĠProblem ( StatusCode s . CONF LI CT , ĠStatus Codes . CONF LI CT _ STRING ) ĊĠĠĠĠĠĠĠ Ġval ĠPRE CONDITION _ FAILED Ġ= ĠProblem ( StatusCode s . PRE CONDITION _ FAILED , ĠStatus Codes . PRE CONDITION _ FAILED _ STRING ) ĊĠĠĠĠĠĠĠ Ġval ĠINTERNAL _ SERVER _ ERROR Ġ= ĠProblem ( StatusCode s . INTERNAL _ SERVER _ ERROR , ĠStatus Codes . INTERNAL _ SERVER _ ERROR _ STRING ) ĊĠĠĠĠĠĠĠ Ġval ĠNOT _ FOUND Ġ= ĠProblem ( StatusCode s . NOT _ FOUND , ĠStatus Codes . NOT _ FOUND _ STRING ) ĊĠĠĠ Ġ} Ċ } Ċ Ċ fun ĠHttp Server Exchange . respond With ( statusCode : ĠInt , Ġvalue : ĠAny ) Ġ{ ĊĠĠĠ Ġthis . respond With ( Response Object ( statusCode , Ġvalue )) Ċ } Ċ Ċ fun ĠHttp Server Exchange . respond With ( problem : ĠProblem ) Ġ{ ĊĠĠĠ Ġthis . respond With ( problem . status , Ġproblem ) Ċ } Ċ Ċ fun ĠHttp Server Exchange . respond With ( response : ĠResponse Object ) Ġ{ ĊĠĠĠ Ġthis . put Attachment ( Marshal ing Filter . RESPONSE _ OBJECT _ KEY , Ġresponse ) Ċ } Ċ