@Singleton public class BodyConverterSelector extends Object
BodyParser
or BodyFormatter
using media
types.
. Examples:
// selector with html and json converters selector = new BodyConverterSelector(Sets.newLinkedHashSet(html, json)); // asking for html, produces the html converter assertEquals(html, selector.get(MediaType.html)); // asking for json, produces the json converter assertEquals(json, selector.get(MediaType.json)); // asking for * / *, produces the first matching converter assertEquals(html, selector.get(MediaType.all));
Constructor and Description |
---|
BodyConverterSelector(Set<BodyParser> parsers,
Set<BodyFormatter> formatters)
Creates a new
BodyConverterSelector . |
Modifier and Type | Method and Description |
---|---|
Optional<BodyFormatter> |
formatter(Object message,
Iterable<MediaType> types) |
Optional<BodyParser> |
parser(com.google.inject.TypeLiteral<?> type,
Iterable<MediaType> types) |
@Inject public BodyConverterSelector(Set<BodyParser> parsers, Set<BodyFormatter> formatters)
BodyConverterSelector
.parsers
- The available body parsers in the system.formatters
- The available body formatters in the system.public Optional<BodyParser> parser(com.google.inject.TypeLiteral<?> type, Iterable<MediaType> types)
public Optional<BodyFormatter> formatter(Object message, Iterable<MediaType> types)
Copyright © 2015. All rights reserved.