private static Err handle406or415(final Set<Route.Definition> routeDefs, final String method, final String path, final MediaType contentType, final List<MediaType> accept) { for (Route.Definition routeDef : routeDefs) { Optional<Route> route = routeDef.matches(method, path, MediaType.all, MediaType.ALL); if (route.isPresent() && !route.get().pattern().contains("*")) { if (!routeDef.canProduce(accept)) { return new Err(Status.NOT_ACCEPTABLE, accept.stream() .map(MediaType::name) .collect(Collectors.joining(", "))); } if (!contentType.isAny()) { return new Err(Status.UNSUPPORTED_MEDIA_TYPE, contentType.name()); } } } return null; }
@Override public Object parse(final TypeLiteral<?> type, final Context ctx) throws Throwable { MediaType ctype = ctx.type(); if (ctype.isAny()) { // */* return ctx.next(); } JavaType javaType = mapper.constructType(type.getType()); if (matcher.matches(ctype) && mapper.canDeserialize(javaType)) { return ctx .ifparam(values -> mapper.readValue(values.iterator().next(), javaType)) .ifbody(body -> mapper.readValue(body.bytes(), javaType)); } return ctx.next(); }
@Override public Object parse(final TypeLiteral<?> type, final Context ctx) throws Throwable { MediaType ctype = ctx.type(); if (ctype.isAny()) { // */* return ctx.next(); } if (ctype.matches(this.type)) { return ctx .ifbody(body -> gson.fromJson(body.text(), type.getType())) .ifparam(values -> gson.fromJson(values.first(), type.getType())); } return ctx.next(); }
@Override public Object parse(final TypeLiteral<?> type, final Context ctx) throws Throwable { MediaType ctype = ctx.type(); if (ctype.isAny()) { // */* return ctx.next(); } if (ctype.matches(this.type)) { return ctx .ifbody(body -> jsonb.fromJson(body.text(), type.getType())) .ifparam(values -> jsonb.fromJson(values.first(), type.getType())); } return ctx.next(); }
private static Err handle406or415(final Set<Route.Definition> routeDefs, final String method, final String path, final MediaType contentType, final List<MediaType> accept) { for (Route.Definition routeDef : routeDefs) { Optional<Route> route = routeDef.matches(method, path, MediaType.all, MediaType.ALL); if (route.isPresent() && !route.get().pattern().contains("*")) { if (!routeDef.canProduce(accept)) { return new Err(Status.NOT_ACCEPTABLE, accept.stream() .map(MediaType::name) .collect(Collectors.joining(", "))); } if (!contentType.isAny()) { return new Err(Status.UNSUPPORTED_MEDIA_TYPE, contentType.name()); } } } return null; }
@Override public Object parse(final TypeLiteral<?> type, final Context ctx) throws Throwable { MediaType ctype = ctx.type(); if (ctype.isAny()) { // */* return ctx.next(); } if (ctype.matches(this.type)) { return ctx .ifbody(body -> gson.fromJson(body.text(), type.getType())) .ifparam(values -> gson.fromJson(values.first(), type.getType())); } return ctx.next(); }
@Override public Object parse(final TypeLiteral<?> type, final Context ctx) throws Throwable { MediaType ctype = ctx.type(); if (ctype.isAny()) { // */* return ctx.next(); } JavaType javaType = mapper.constructType(type.getType()); if (matcher.matches(ctype) && mapper.canDeserialize(javaType)) { return ctx .ifparam(values -> mapper.readValue(values.iterator().next(), javaType)) .ifbody(body -> mapper.readValue(body.bytes(), javaType)); } return ctx.next(); }