public RestTemplateBuilder withSpecificJsonMessageConverter() { isUseDefaultJsonMessageConverter = false; AbstractHttpMessageConverter<?> jsonMessageConverter = new MappingJackson2HttpMessageConverter( Jackson2ObjectMapperBuilder .json() .featuresToEnable( DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT) .build()); jsonMessageConverter.setSupportedMediaTypes(Lists.newArrayList( MediaType.TEXT_HTML, MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON)); withMessageConverter(jsonMessageConverter); return this; }
private void writeInternal(Object object, HttpOutputMessage outputMessage) throws Exception { Method method = AbstractHttpMessageConverter.class.getDeclaredMethod( "writeInternal", Object.class, HttpOutputMessage.class); method.setAccessible(true); method.invoke(this.converter, object, outputMessage); }