Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

shardingsphere-jdbc-5.5.0 causes spring boot to return JSON data as XML #31203

Open
Comven opened this issue May 11, 2024 · 5 comments
Open

shardingsphere-jdbc-5.5.0 causes spring boot to return JSON data as XML #31203

Comven opened this issue May 11, 2024 · 5 comments

Comments

@Comven
Copy link

Comven commented May 11, 2024

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>
@linghengqian
Copy link
Member

@Comven
Copy link
Author

Comven commented May 11, 2024

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

@linghengqian
Copy link
Member

  • @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 Removes use of JAXB API via jackson-dataformat-xml #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.

@linghengqian
Copy link
Member

@lazeyliu @Comven

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants