0

Although I apply the XML annotation, I can't get results in Xml format when I query it. Can you help me?

Although I apply the XML annotation, I can't get results in Xml format when I query it. Can you help?

I am also using the json plugin, I opened this result in the hidden chrome page

POM.XML

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.javaegitimleri</groupId>
  <artifactId>petclinic</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>
  <parent>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-parent</artifactId>
      <version>2.1.1.RELEASE</version>
  </parent>
  <dependencies>
      <dependency>
          <groupId>junit</groupId>
          <artifactId>junit</artifactId>
          <scope>test</scope>
      </dependency>
      <dependency>
          <groupId>org.hamcrest</groupId>
          <artifactId>hamcrest-library</artifactId>
          <scope>test</scope>
      </dependency>
      <dependency>
          <groupId>org.apache.tomcat.embed</groupId>
          <artifactId>tomcat-embed-jasper</artifactId>
      </dependency>
      <dependency>
          <groupId>javax.servlet</groupId>
          <artifactId>jstl</artifactId>
      </dependency>
      <dependency>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-web</artifactId>
      </dependency>
      <dependency>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-actuator</artifactId>
      </dependency>
      <dependency>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-devtools</artifactId>
          <optional>true</optional>
      </dependency>
      <dependency>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-configuration-processor</artifactId>
          <optional>true</optional>
      </dependency>
      <dependency>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-thymeleaf</artifactId>
      </dependency>
      <dependency>
          <groupId>javax.xml.bind</groupId>
          <artifactId>jaxb-api</artifactId>
          <version>2.1</version>
      </dependency>
  </dependencies>
  <properties>
      <java.version>1.8</java.version>
  </properties>
  <build>
      <plugins>
          <plugin>
              <groupId>org.springframework.boot</groupId>
              <artifactId>spring-boot-maven-plugin</artifactId>
          </plugin>
      </plugins>
  </build>
</project>

Owner.java

package com.javaegitimleri.petclinic.model;

    import java.util.HashSet;
    import java.util.Set;
    
    import javax.xml.bind.annotation.XmlRootElement;
    import javax.xml.bind.annotation.XmlTransient;
    
    import com.fasterxml.jackson.annotation.JsonIgnore;
    
    @XmlRootElement
    public class Owner {
      private Long id;
      private String firstName;
      private String lastName;
      
      private Set<Pet> pets = new HashSet<>();
    
      public Long getId() {
          return id;
      }
    
      public void setId(long id) {
          this.id = id;
      }
    
      public String getFirstName() {
          return firstName;
      }
    
      public void setFirstName(String firstName) {
          this.firstName = firstName;
      }
    
      public String getLastName() {
          return lastName;
      }
    
      public void setLastName(String lastName) {
          this.lastName = lastName;
      }
    
      @XmlTransient
      @JsonIgnore
      public Set<Pet> getPets() {
          return pets;
      }
    
      public void setPets(Set<Pet> pets) {
          this.pets = pets;
      }
    
      @Override
      public String toString() {
          return "Owner [id=" + id + ", firstName=" + firstName + ", lastName=" + lastName + "]";
      }
      
      
      
      
    }

aplication.properties

management.endpoints.enabled-by-default=false

petclinic.display-owners-with-pets=true

spring.mvc.view.prefix=/WEB-INF/jsp
spring.mvc.view.suffix=.jsp

spring.resources.chain.strategy.content.enabled=true
spring.thymeleaf.enabled=false
spring.mvc.contentnegotiation.favor-path-extension=true
spring.mvc.pathmatch.use-suffix-pattern=true

RESULT

enter image description here

NEW RESULT enter image description here

devxpe
  • 32
  • 6
  • Does this answer your question? [javax.xml.bind.JAXBException Implementation of JAXB-API has not been found on module path or classpath](https://stackoverflow.com/questions/51916221/javax-xml-bind-jaxbexception-implementation-of-jaxb-api-has-not-been-found-on-mo) – Coderino Javarino Oct 12 '21 at 07:12

1 Answers1

0

I solved solution by searching on website!

We should to add these codes to POM.XML

  <dependency>
    <groupId>javax.activation</groupId>
    <artifactId>activation</artifactId>
    <version>1.1</version>
  </dependency>

  <dependency>
    <groupId>org.glassfish.jaxb</groupId>
    <artifactId>jaxb-runtime</artifactId>
  </dependency>

Source of the solution link!

devxpe
  • 32
  • 6