Spray is actually looking into the Accept
header value and validates against it. So if route is returning application/json
or text/plain
and client accepts image/jpeg
than spray will return 406 Not Acceptable
. If client will request application/json
ortext/plain
from this route than he will receive repsonse with matching Content-Type.
The main trick here is to use correct marshallers for return objects. You can read more about marshalling here.
Also you can override MediaType with respondWithMediaType directive, but I think it is better to use correct marshallers.