OpenAPITools / OpenAPITools/openapi-generator
[BUG] (JAVA 11 Native HTTP client) No mapper for XML instantiated, thus fails with `JsonParseException: Unexpected character ('<' (code 60))`
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Generated a client for an API that sends XML output exclusively using the java generator with <library>native</library> (ping @bbdouglas).
It correctly adds header("Accept", "application/xml") to the HttpRequest, but however fails on executing any of the endpoint methods with
org.openapitools.client.ApiException: com.fasterxml.jackson.core.JsonParseException: Unexpected character ('<' (code 60)): expected a valid value (JSON String, Number, Array, Object or token 'null', 'true' or 'false') at [Source: (jdk.internal.net.http.ResponseSubscribers$HttpResponseInputStream); line: 1, column: 2]
java.lang.RuntimeException: org.openapitools.client.ApiException: com.fasterxml.jackson.core.JsonParseException: Unexpected character ('<' (code 60)): expected a valid value (JSON String, Number, Array, Object or token 'null', 'true' or 'false')
as the mapper being used is the default JSON mapper, while it should use a new com.fasterxml.jackson.dataformat.xml.XmlMapper instead in this case.
openapi-generator version
7.4
Suggest a fix
The obvious (and working) fix is to use an XmlMapper instead of ObjectMapper for Deserialization (the readValue() api is identical) whenever application/xml is requested.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the generated Java 11 native HTTP client deserialization path and inspect how an application/xml response is mapped. Compare the current default JSON mapper behavior with the proposed XmlMapper approach; done means an XML-only API response can be deserialized without the reported JsonParseException.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100