xml - Java 8 default methods, JAXB, and JavaFX Property frustrations -
there way use jaxb annotations on default methods inherited java 8 interfaces?
i created sample maven project @ https://github.com/ruckc/jaxb-java8-javafx highlighting shims required do.
in dealing javafx properties, i've found can use default methods on interfaces remove annoying getters/setters data object.
public interface named { @xmlattribute(name="name") default string getname() { return nameproperty().get(); } default void setname(string name) { nameproperty().set(name); } stringproperty nameproperty(); }
this removes alot of redundant code inside implementations. issue now, when trying marshall objects using jaxb, still have implement methods (annotated @shim
) in implementations, annotations picked up.
@xmlrootelement(name="business") public class business implements named { private final stringproperty nameproperty = new simplestringproperty(); @shim @override public void setname(string name) { named.super.setname(name); } @shim @xmlattribute(name="name") @override public string getname() { return named.super.getname(); } @override public stringproperty nameproperty() { return nameproperty; } }
in short, if remove @shim
printed out xml main
method doesn't contain name attribute, , printed out name attribute unmarshalled string null. i'd avoiding spurious/duplicate code.
Comments
Post a Comment