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
   
![image](https://github.com/apache/shardingsphere/assets/8464801/59c4a972-76a9-4920-9b1a-6ab3b0901336)
   
   Accessing this interface address directly in a browser yields the following 
results
   
![image](https://github.com/apache/shardingsphere/assets/8464801/999636a5-ecf0-4372-b9ec-ac6ceb36347e)
   


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to