'Rest api, adding another MediaType, default response

I have REST api in Spring MVC that is used commonly by many users. Let's say I have endpoint like that:

@GET
@Path("/getNumber")
@Produces({ MediaType.TEXT_PLAIN })
public String getNumber(Long id) {
    return service.getNumber(id);
}

Now I would like to add another media type, APPLICATION_JSON, to annotation @Produces. May that cause some problems with user apps that are using this endpoint? For example when they are not specyfing header with response type and are expecting response message will be text, may this change cause that they will get response in json and in result integration with this api will fail?



Solution 1:[1]

Content negotiation strategy can be used for this .Please refer this https://spring.io/blog/2013/05/11/content-negotiation-using-spring-mvc

Solution 2:[2]

As a best practice common used Media-Type is XML or Json, but mostly Json because it is less verbose than XML. I suggest you this post. Even if you want to set a default type, it should be Json.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Tushar Wason
Solution 2 Harry Coder