JaxB marhsalling przy użyciu interfejsów
Mam następującą klasę, chcę być w stanie produkować xml dynamicznie w oparciu o interfejs, ze zmieniającymi się implementacjami ... czy to możliwe ... Próbowałem z małym szczęściem ...
@xmlRootElement
public class Vehicles {
private String id;
private List<VehicleType> types;
.... various setters and getters...
... with annotated getters...
}
public interface VehicleType {
public String getName();
}
public Car implements VehicleType {
private String name;
private String wheels;
...various constructors...
@XmlElement
public String getName() {
return name;
}
@XmlElement
public String getWheels() {
return wheels;
}
}
public Motorbike implements VehicleType {
private String name;
private String exhaust;
...various constructors...
@XmlElement
public String getName() {
return name;
}
@XmlElement
public String getExhaust() {
return exhaust;
}
}
Chcę, aby pojazdy do przewozu pojazdów produkowały następujące wyjścia:
<vehicles>
<types>
<car>
..car specific elements
</car>
<motorbike>
.. mototrbike specific elements
<motorbike>
</types>
</vehicles>
Klasa pojazdów nie może wiedzieć o implementacjach lub które istnieją .. wie tylko o interfejsie, który tutaj naprawdę wykorzystuję jako interfejs znacznika .. aby umożliwić mi wypełnienie listy różnymi implementacjami w czasie wykonywania ...
Czy mimo to mogę uzyskać jaxb, aby renderować dane wyjściowe jako xml bez rodziców naprawdę wiedząc o implementacjach?