Skip to content

Commit c324628

Browse files
authored
Update dropwizard marshaller (RustedBones#138)
1 parent 3705532 commit c324628

File tree

1 file changed

+4
-14
lines changed

1 file changed

+4
-14
lines changed

dropwizard-v5/src/main/scala/fr/davit/pekko/http/metrics/dropwizard/marshalling/DropwizardMarshallers.scala

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,28 +16,18 @@
1616

1717
package fr.davit.pekko.http.metrics.dropwizard.marshalling
1818

19-
import java.io.StringWriter
20-
2119
import org.apache.pekko.http.scaladsl.marshalling.{Marshaller, ToEntityMarshaller}
22-
import org.apache.pekko.http.scaladsl.model.{ContentTypes, HttpEntity}
2320
import com.fasterxml.jackson.databind.ObjectMapper
2421
import fr.davit.pekko.http.metrics.dropwizard.DropwizardRegistry
22+
import org.apache.pekko.http.scaladsl.model.MediaTypes
2523

2624
trait DropwizardMarshallers {
2725

2826
implicit val registryToEntityMarshaller: ToEntityMarshaller[DropwizardRegistry] = {
29-
3027
val writer = new ObjectMapper().writer()
31-
32-
Marshaller.opaque { registry =>
33-
val output = new StringWriter()
34-
try {
35-
writer.writeValue(output, registry.underlying)
36-
HttpEntity(output.toString).withContentType(ContentTypes.`application/json`)
37-
} finally {
38-
output.close()
39-
}
40-
}
28+
Marshaller
29+
.stringMarshaller(MediaTypes.`application/json`)
30+
.compose(registry => writer.writeValueAsString(registry.underlying))
4131
}
4232
}
4333

0 commit comments

Comments
 (0)