Mapear Objeto para gerar XML correto com JAXB

1 resposta
javer

Pessoal,

Tenho esse objeto:
import java.io.Serializable;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;

@SuppressWarnings("serial")
@Entity
@XmlAccessorType(XmlAccessType.FIELD)
@Table(uniqueConstraints = @UniqueConstraint(columnNames = "id"))
public class DriverDoor implements Serializable {

	@Id
	@GeneratedValue
	private Long id;

	@XmlAttribute
	private String changed;

	private String valor;
	
	public Long getId() {
		return id;
	}

	public String getValor() {
		return valor;
	}

	public void setValor(String valor) {
		this.valor = valor;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getChanged() {
		return changed;
	}

	public void setChanged(String changed) {
		this.changed = changed;
	}
}
Preciso que seja gerado um XML com esse com o JAXB:
<driver_door changed="false">Closed</driver_door>
Não estou conseguindo, no meu tá saindo assim:
<driverDoor changed="changed"><valor>Closed</valor></driverDoor>
Porém se trata apenas de uma parte de um XML maior:
<response>
    <status iccid="434384833343">
        <doors changed="changed" locked="Unlocked">
            <driverDoor changed="changed">
                <valor>Closed</valor>
            </driverDoor>
            <passengerDoor>fechada</passengerDoor>
            <rearLeftDoor>aberta</rearLeftDoor>
            <rearRightDoor>aberta</rearRightDoor>
            <trunk>fechado</trunk>
        </doors>
    </status>
</response>
Quem pode dar uma dica?

1 Resposta

campelo.m

Faça algo como:

@XmlRootElement(name = "driver_door")
public class DriverDoor implements Serializable {

para que o changed retorne true ou false ela deve ser do tipo boolean

Criado 6 de agosto de 2014
Ultima resposta 8 de ago. de 2014
Respostas 1
Participantes 2