You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by "Comven (via GitHub)" <gi...@apache.org> on 2024/05/11 02:06:29 UTC
[I] shardingsphere-jdbc-5.5.0 causes spring boot to return JSON data as XML [shardingsphere]
Comven opened a new issue, #31203:
URL: https://github.com/apache/shardingsphere/issues/31203
spring-boot: 2.7.18、3.2.4
shardingsphere-jdbc:5.5.0
The introduction of the 'jackson-dataformat-xml' component dependency in version 5.5 resulted in the JSON returned by the spring boot program being changed to XML format.
shardingsphere-jdbc-core-5.4.1 Return format is
```
[
{
"id": 1,
"name": "ZhangSan",
"address": "BeiJing",
"addTime": "2024-05-11 10:05:10"
}
]
```
shardingsphere-jdbc-5.5.0 Return format is
```
<List>
<item>
<id>1</id>
<name>ZhangSan</name>
<address>BeiJing</address>
<addTime>2024-05-11 09:48:56</addTime>
</item>
</List>
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] shardingsphere-jdbc-5.5.0 causes spring boot to return JSON data as XML [shardingsphere]
Posted by "linghengqian (via GitHub)" <gi...@apache.org>.
linghengqian commented on issue #31203:
URL: https://github.com/apache/shardingsphere/issues/31203#issuecomment-2105658808
@lazeyliu @Comven
- I'm pretty sure this issue still lacks real unit testing. Although we can see many similar issues so far, including but not limited to,
- https://stackoverflow.com/questions/66752245
- https://stackoverflow.com/questions/57706610
- https://stackoverflow.com/questions/41036377
- https://hafuhafu.com/archives/springboot-jackson-xml-result-json/
- https://github.com/spring-projects/spring-boot/issues/32494
- https://github.com/spring-projects/spring-boot/issues/32647
- #31067
- So far, no issue has actually provided git with unit tests. The results I've seen from reasonable unit tests and https://github.com/spring-projects/spring-boot/issues/32494#issuecomment-1268851718 should be consistent.
```
With the expected xml dependency
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'com.fasterxml.jackson.dataformat:jackson-dataformat-xml'
the following controller:
@RestController
public class JsonXmlController {
@GetMapping("/book")
public Book book() {
return new Book("Intro to Spring Boot", "Spring team");
}
public record Book(String title, String author) {
}
}
I'm getting the following behavior:
http localhost:8080/book -v
GET /book HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate
Connection: keep-alive
Host: localhost:8080
User-Agent: HTTPie/3.2.1
HTTP/1.1 200
Connection: keep-alive
Content-Type: application/json
Date: Wed, 05 Oct 2022 19:14:27 GMT
Keep-Alive: timeout=60
Transfer-Encoding: chunked
{
"author": "Spring team",
"title": "Intro to Spring Boot"
}
```
- I have every reason to believe that you should provide unit tests first, and unit tests are probably completely unrelated to shardingsphere.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] shardingsphere-jdbc-5.5.0 causes spring boot to return JSON data as XML [shardingsphere]
Posted by "linghengqian (via GitHub)" <gi...@apache.org>.
linghengqian commented on issue #31203:
URL: https://github.com/apache/shardingsphere/issues/31203#issuecomment-2128840603
- @Comven So, this is actually an issue with Spring Framework's WebMVC. Even if `jackson-dataformat-xml` is not used and instead, xstream or another XML parsing library is utilized, the problem would still arise if one were to implement an `AbstractGenericHttpMessageConverter` akin to `MappingJackson2XmlHttpMessageConverter`. I lean towards this being an issue that should be raised at https://github.com/spring-projects/spring-framework/issues , specifically that merely introducing `jackson-dataformat-xml` should not activate the `MappingJackson2XmlHttpMessageConverter`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] shardingsphere-jdbc-5.5.0 causes spring boot to return JSON data as XML [shardingsphere]
Posted by "linghengqian (via GitHub)" <gi...@apache.org>.
linghengqian commented on issue #31203:
URL: https://github.com/apache/shardingsphere/issues/31203#issuecomment-3005109201
As a review of https://github.com/apache/shardingsphere/issues/26041 and the spring boot 4 snapshot version, I think it is necessary to use spi instead of xml. Because jackson 3 is about to increase the minimum jdk runtime version to jdk17, and shardingsphere currently parses xml through the jackson xml module, which will further cause confusion related to spring boot 4.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] shardingsphere-jdbc-5.5.0 causes spring boot to return JSON data as XML [shardingsphere]
Posted by "linghengqian (via GitHub)" <gi...@apache.org>.
linghengqian commented on issue #31203:
URL: https://github.com/apache/shardingsphere/issues/31203#issuecomment-3047848716
- Then again, since https://github.com/apache/shardingsphere/pull/35918 changed `org.apache.shardingsphere.mode.repository.standalone.jdbc.JDBCRepository#isDefault()` from `true` to `false`, it seems meaningless to keep this issue open. Because we are discussing an optional module. It is OK for optional modules to do anything.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] shardingsphere-jdbc-5.5.0 causes spring boot to return JSON data as XML [shardingsphere]
Posted by "linghengqian (via GitHub)" <gi...@apache.org>.
linghengqian commented on issue #31203:
URL: https://github.com/apache/shardingsphere/issues/31203#issuecomment-2105547590
- Neither you nor #31067 provide unit tests, and the issue is clearly a spring boot configuration issue. The deeper question subject to a third party spring boot starter automatically configure class. I would encourage you to write unit tests first and send them to spring boot.
- For https://github.com/spring-projects/spring-boot/issues/32494 and https://github.com/spring-projects/spring-boot/issues/32647 .
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] shardingsphere-jdbc-5.5.0 causes spring boot to return JSON data as XML [shardingsphere]
Posted by "linghengqian (via GitHub)" <gi...@apache.org>.
linghengqian commented on issue #31203:
URL: https://github.com/apache/shardingsphere/issues/31203#issuecomment-2153764094
- If no one is willing to investigate on the Spring Framework side, I will revisit this issue in two months and try to introduce a draft into the Spring Framework OSS 6.3.0-M1.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] shardingsphere-jdbc-5.5.0 causes spring boot to return JSON data as XML [shardingsphere]
Posted by "Comven (via GitHub)" <gi...@apache.org>.
Comven commented on issue #31203:
URL: https://github.com/apache/shardingsphere/issues/31203#issuecomment-2128340940
> @lazeyliu @Comven
>
> * I'm pretty sure this issue still lacks real unit testing. Although we can see many similar issues so far, including but not limited to,
>
> * https://stackoverflow.com/questions/66752245
> * https://stackoverflow.com/questions/57706610
> * https://stackoverflow.com/questions/41036377
> * https://hafuhafu.com/archives/springboot-jackson-xml-result-json/
> * [MappingJackson2XmlHttpMessageConverterConfiguration and spring.xml.ignore property spring-projects/spring-boot#32494](https://github.com/spring-projects/spring-boot/issues/32494)
> * [Adding jackson dataformat xml should not change output format to xml automatically spring-projects/spring-boot#32647](https://github.com/spring-projects/spring-boot/issues/32647)
> * [SpringBoot project return format is not json #31067](https://github.com/apache/shardingsphere/issues/31067)
> * So far, no issue has actually provided git with unit tests. The results I've seen from reasonable unit tests and [MappingJackson2XmlHttpMessageConverterConfiguration and spring.xml.ignore property spring-projects/spring-boot#32494 (comment)](https://github.com/spring-projects/spring-boot/issues/32494#issuecomment-1268851718) should be consistent.
>
> ```
> With the expected xml dependency
>
> implementation 'org.springframework.boot:spring-boot-starter-web'
> implementation 'com.fasterxml.jackson.dataformat:jackson-dataformat-xml'
>
> the following controller:
>
> @RestController
> public class JsonXmlController {
> @GetMapping("/book")
> public Book book() {
> return new Book("Intro to Spring Boot", "Spring team");
> }
> public record Book(String title, String author) {
> }
> }
>
> I'm getting the following behavior:
>
> http localhost:8080/book -v
> GET /book HTTP/1.1
> Accept: */*
> Accept-Encoding: gzip, deflate
> Connection: keep-alive
> Host: localhost:8080
> User-Agent: HTTPie/3.2.1
>
>
>
> HTTP/1.1 200
> Connection: keep-alive
> Content-Type: application/json
> Date: Wed, 05 Oct 2022 19:14:27 GMT
> Keep-Alive: timeout=60
> Transfer-Encoding: chunked
>
> {
> "author": "Spring team",
> "title": "Intro to Spring Boot"
> }
> ```
>
> * I have every reason to believe that you should provide unit tests first, and unit tests are probably completely unrelated to shardingsphere.
I have said earlier that this bug is due to jackson-dataformat-xml, but shardingsphere-5.5.0 uses the functionality of this component to cause such problems in programs that introduce shardingsphere-jdbc, which is relevant. That's why I said can you switch back to jaxb parsing xml instead of jackson-dataformat-xml, otherwise jackson-dataformat-xml has always had this problem without changing, Our projects using shardingsphere-jdbc-5.5.0 need to deal specifically with the issue of the response data being returned in xml。
The problem of replicating jackson-dataformat-xml is relatively easy。
spring-boot-2.7.18 or later,Introduce the following since coordinates
```
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
```
Write a piece of logic that returns JSON content, as shown in the following code

Accessing this interface address directly in a browser yields the following results

--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] shardingsphere-jdbc-5.5.0 causes spring boot to return JSON data as XML [shardingsphere]
Posted by "linghengqian (via GitHub)" <gi...@apache.org>.
linghengqian commented on issue #31203:
URL: https://github.com/apache/shardingsphere/issues/31203#issuecomment-2294625998
- I've done some more interesting tracking on this issue, and I reasonably believe that this is one of Mozilla's shit-hills of code, and Chrome is just perfectly inheriting Mozilla's conventions.
- This is actually https://developer.mozilla.org/en-US/docs/Web/HTTP/Content_negotiation/List_of_default_Accept_values which is a constraint for all browsers.
> User Agent: Firefox 128 and later [1]
> Value: `text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/png,image/svg+xml,*/*;q=0.8`
- This is documented at https://github.com/spring-projects/spring-boot/blob/v3.3.2/spring-boot-project/spring-boot-docs/src/docs/antora/modules/how-to/pages/spring-mvc.adoc#write-an-xml-rest-service and https://github.com/spring-projects/spring-boot/blob/v3.3.2/spring-boot-project/spring-boot-docs/src/docs/antora/modules/how-to/pages/spring-mvc.adoc#write-a-json-rest-service .
- Be responsible. Choose `Custom @ResponseBody rendering` or `Custom Jackson ObjectMapper` as required by Spring Boot.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] shardingsphere-jdbc-5.5.0 causes spring boot to return JSON data as XML [shardingsphere]
Posted by "Comven (via GitHub)" <gi...@apache.org>.
Comven commented on issue #31203:
URL: https://github.com/apache/shardingsphere/issues/31203#issuecomment-2105597608
Can `shardingsphere-jdbc` be made to not rely on the `jackson-dataformat-xml` component package, otherwise using the `shardingsphere-jdbc-.5.5.0`, the spring boot program will not be able to return `JSON` properly? Originally, our business program did not introduce this problematic `jackson-dataformat-xml` component package because shardingsphere jdbc automatically introduced this package, which caused this problem. @linghengqian
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] shardingsphere-jdbc-5.5.0 causes spring boot to return JSON data as XML [shardingsphere]
Posted by "terrymanu (via GitHub)" <gi...@apache.org>.
terrymanu closed issue #31203: shardingsphere-jdbc-5.5.0 causes spring boot to return JSON data as XML
URL: https://github.com/apache/shardingsphere/issues/31203
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] shardingsphere-jdbc-5.5.0 causes spring boot to return JSON data as XML [shardingsphere]
Posted by "linghengqian (via GitHub)" <gi...@apache.org>.
linghengqian commented on issue #31203:
URL: https://github.com/apache/shardingsphere/issues/31203#issuecomment-2225419104
From my point of view, this is actually a problem with Google Chrome, because your http request gives too high a priority to XML. I suggest you file an issue against Spring Boot on the Chromium side. Refer to https://www.chromium.org/for-testers/bug-reporting-guidelines/ .
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] shardingsphere-jdbc-5.5.0 causes spring boot to return JSON data as XML [shardingsphere]
Posted by "linghengqian (via GitHub)" <gi...@apache.org>.
linghengqian commented on issue #31203:
URL: https://github.com/apache/shardingsphere/issues/31203#issuecomment-2105600198
- @Comven Shardingsphere always needs a library for parsing xml files. In the past it was JAXB API, now it is `jackson-dataformat-xml`, and it can also be `xstream` in the future. The reason has been explained clearly in #29384 . Using `jackson-dataformat-xml` will allow shardingsphere to better protect against breaking changes in Spring Boot 3.x and GraalVM Native Image.
- You **must provide** unit tests to prove why just introducing `jackson-dataformat-xml` will cause WebMVC or Webflux in Spring Boot to actually change the return value of the Controller. There have been 4 issues so far, and no one has provided a minimal unit test.
- Prove it. I believe this is 100% a problem with Spring Boot or a third-party Spring Boot Stater, because there is no reason to change the configuration of Spring Boot by just introducing `jackson-dataformat-xml`, which is just an xml parsing library.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] shardingsphere-jdbc-5.5.0 causes spring boot to return JSON data as XML [shardingsphere]
Posted by "lazeyliu (via GitHub)" <gi...@apache.org>.
lazeyliu commented on issue #31203:
URL: https://github.com/apache/shardingsphere/issues/31203#issuecomment-2105655862
I had the same problem again and found others who also had the same problem as follows:
https://stackoverflow.com/questions/41036377/spring-mvc-changing-default-response-format-from-xml-to-json
https://stackoverflow.com/questions/66752245/spring-5-jackson-dataformat-xml-forces-responsebody-with-xml
https://stackoverflow.com/questions/57706610/how-to-set-default-messageconverter-to-json-with-jackson-dataformat-xml-add ed
And a Chinese developer analyzed the reason:
https://hafuhafu.com/archives/springboot-jackson-xml-result-json/
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] shardingsphere-jdbc-5.5.0 causes spring boot to return JSON data as XML [shardingsphere]
Posted by "linghengqian (via GitHub)" <gi...@apache.org>.
linghengqian closed issue #31203: shardingsphere-jdbc-5.5.0 causes spring boot to return JSON data as XML
URL: https://github.com/apache/shardingsphere/issues/31203
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org