Simple string as JSON return value in spring rest controller

前端 未结 4 1810
离开以前
离开以前 2020-12-17 16:58

Let\'s take a look at the following simple test controller (Used with Spring 4.0.3):

@RestController
public class Te         


        
4条回答
  •  伪装坚强ぢ
    2020-12-17 17:29

    You can remove the StringHttpMessageConverter which is registered before the jackson converter, - like mentioned in the comment.

    /**
     * Unregister the default {@link StringHttpMessageConverter} as we want
     * Strings to be handled by the JSON converter.
     *
     * Our MappingJackson2HttpMessageConverter will deal with strings.
     *
     * @param converters
     *            List of already configured converters
     */
    @Override
    public void extendMessageConverters(List> converters) {
        converters.removeIf(converter -> converter instanceof StringHttpMessageConverter);
    }
    

提交回复
热议问题