For some weeks I have been working on rest api using spring -mvc. The REST-API is working correctly, and I almost do until the last problem when it comes to handling errors using specific error objects.
The REST API uses JSON as a format for serializing Java objects. If an error occurs during the execution of the service, a specific error object is created and sent back to the client.
Everything works fine when my leisure services are marked as "produces = application / json". But there are also some services that should return only plain text using "results = text / plain". If an error occurs in one of these services, spring-MVC will throw an HttpMediaTypeNotAcceptableException. It seems correct, the client is requesting a text / plain text type, but the server response is "application / json".
Can you say what is the right solution for this problem?
Only using JSON as the type of response content and wrapping plain text is always in a special class object. => I don't seem to like REST because REST should support several types of content.
Each service serving the "text" will be marked as "produces = application / json; text / plain", and the client also needs to send both to the "accept-header". => In doing so, the API API seems to support two types of content for the same resource. But this is wrong. Only in case of an error the API will return JSON, otherwise it will always be "text".
It sounds to me like a really special REST question and cannot find related questions on this topic.
Vhaos source
share