0

I got following XML with element name being present with their package name. How can I marshal/unmarshal the given XML using JaxB?

<com.jaraws.api.Vehicle>
  <number>KT12356</number>
  <engine>DIESEL<engine>
</com.jaraws.api.Vehicle>

With Java class being written as:

package com.jaraws.api;

@XmlRootElement
public class Vehicle{
  private String number;
  private String engine;

  // Getters Setter for number and engine attributes
  @XmlElement
  public String getNumber(){
    return number;
  }

  public void setNumber(){
    this.number=number;
  }

  @XmlElement
  public String getEngine(){
    return engine;
  }

  public void setEngine(){
    this.engine=engine;
  }
}

Is it achievable or I am not doing something in a right matter. I want to marshal / unmarshal the xml in given format only.

Jaraws
  • 581
  • 1
  • 7
  • 24
  • Did you tried to add a name to the root element? ...like @XmlRootElement(name = "com.jaraws.api.Vehicle") – Thomas W. Dec 09 '22 at 17:58
  • @xerx593 and Thomas, if that's the only way of doing that? Can't I avoid writing the package explicitly rather it is getting derived? – Jaraws Dec 09 '22 at 18:01

0 Answers0