colddog
colddog

Reputation: 1

spring app fails to start after adding the dependency jackson-dataformat-xml

I am running a spring boot application 2.5.6 and I have the following issue: after adding the dependency jackson-dataformat-xml to my pom.xml the application fails to start failing on initializing one of the bean (renamed here to "coocoo"):

{"at":"2023-01-25T06:31:21.818Z","level":"WARN","thread":"main","message":"Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'coocoo': Injection of autowired dependencies failed; nested exception is org.springframework.web.client.RestClientException: Error while extracting response for type [interface java.util.Map] and content type [application/xml;charset=UTF-8]; nested exception is org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Unexpected character '{' (code 123) in prolog; expected '<'\n at [row,col {unknown-source}]: [1,1]; nested exception is com.fasterxml.jackson.core.JsonParseException: Unexpected character '{' (code 123) in prolog; expected '<'\n at [row,col {unknown-source}]: [1,1]","component":"org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext"}

it is important to note that coocoo is init inside a Configuration class I cannot modify, it's an external dependency. investigating seems that during cooco initialization it makes a http call using RestTemplate as follows:

new RestTemplate().exchange(url, HttpMethod.GET, request, Map.class, new Object[0])

since the accept header is not explicitly defined it generates the following value:

Accept=[application/xml, text/xml, application/json, application/cbor, application/*+xml, application/*+json]

and although the response is a json (it even has content-type: application/json;charset=UTF-8), it will try to parse it as a xml, which causes the exception shown above.

is there anyway I can control this flow without changing the configuration class coocoo is in?

I tried implementing a ClientHttpRequestInterceptor that will replace the Accept header, but seems that since RestTemplate is init with "new" the interceptor is never wired in. also tried setting the flag spring.xml.ignore to true, but got the same result.

Upvotes: 0

Views: 226

Answers (0)

Related Questions