@Test public void canChooseOneOfManyUnmarshallers() throws Exception { Unmarshaller<HttpEntity, String> jsonUnmarshaller = Unmarshaller.forMediaType(MediaTypes.APPLICATION_JSON, Unmarshaller.entityToString()) .thenApply((str) -> "json"); Unmarshaller<HttpEntity, String> xmlUnmarshaller = Unmarshaller.forMediaType(MediaTypes.TEXT_XML, Unmarshaller.entityToString()) .thenApply((str) -> "xml"); final Unmarshaller<HttpEntity, String> both = Unmarshaller.firstOf(jsonUnmarshaller, xmlUnmarshaller); { CompletionStage<String> resultStage = both.unmarshall( HttpEntities.create(ContentTypes.TEXT_XML_UTF8, "<suchXml/>"), system().dispatcher(), materializer()); assertEquals("xml", resultStage.toCompletableFuture().get(3, TimeUnit.SECONDS)); } { CompletionStage<String> resultStage = both.unmarshall( HttpEntities.create(ContentTypes.APPLICATION_JSON, "{}"), system().dispatcher(), materializer()); assertEquals("json", resultStage.toCompletableFuture().get(3, TimeUnit.SECONDS)); } }