From 7f4329d64ffc7007601f13cc398025e581570f4b Mon Sep 17 00:00:00 2001 From: Christof Rabensteiner Date: Fri, 23 Aug 2019 14:15:53 +0200 Subject: Fix JAXB Unmarshalling / Conversion Bug - Ensure that moazs creates concrete Persons (CorporateBody, PhysicalPerson), resp. concrete Adresses (InternetAddress, PostalAddress, TelephoneAdress) instead of AbstractPersons or AbstractAdresses during conversion from mzs to msg. Reason: Instances of abstract classes do not conform to the xml scheme. --- .../at/gv/egiz/moazs/scheme/Mzs2MsgConverter.java | 38 +++++++++++++--------- 1 file changed, 23 insertions(+), 15 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/at/gv/egiz/moazs/scheme/Mzs2MsgConverter.java b/src/main/java/at/gv/egiz/moazs/scheme/Mzs2MsgConverter.java index 7dddbf1..f2e6861 100644 --- a/src/main/java/at/gv/egiz/moazs/scheme/Mzs2MsgConverter.java +++ b/src/main/java/at/gv/egiz/moazs/scheme/Mzs2MsgConverter.java @@ -150,17 +150,23 @@ public class Mzs2MsgConverter { return addresses.stream() .map(JAXBElement::getValue) .map(this::convert) - .map(personFactory::createAddress) .collect(toList()); } - private AbstractAddressType convert(at.gv.zustellung.app2mzs.xsd.persondata.AbstractAddressType address) { - if (address instanceof at.gv.zustellung.app2mzs.xsd.persondata.InternetAddressType ) { return convert((at.gv.zustellung.app2mzs.xsd.persondata.InternetAddressType) address); - } else if (address instanceof at.gv.zustellung.app2mzs.xsd.persondata.PostalAddressType ) { return convert((at.gv.zustellung.app2mzs.xsd.persondata.PostalAddressType) address); - } else if (address instanceof at.gv.zustellung.app2mzs.xsd.persondata.TelephoneAddressType) { return convert((at.gv.zustellung.app2mzs.xsd.persondata.TelephoneAddressType) address); - } else { - throw new IllegalArgumentException(format("No conversion strategy of address of type=%s.", address.getClass().toGenericString())); - } + private JAXBElement convert(at.gv.zustellung.app2mzs.xsd.persondata.AbstractAddressType address) { + if (address instanceof at.gv.zustellung.app2mzs.xsd.persondata.InternetAddressType) + return personFactory.createInternetAddress( + convert((at.gv.zustellung.app2mzs.xsd.persondata.InternetAddressType) address)); + + if (address instanceof at.gv.zustellung.app2mzs.xsd.persondata.PostalAddressType) + return personFactory.createPostalAddress( + convert((at.gv.zustellung.app2mzs.xsd.persondata.PostalAddressType) address)); + + if (address instanceof at.gv.zustellung.app2mzs.xsd.persondata.TelephoneAddressType) + return personFactory.createTelephoneAddress( + convert((at.gv.zustellung.app2mzs.xsd.persondata.TelephoneAddressType) address)); + + throw new IllegalArgumentException(format("No conversion strategy for address of type=%s.", address.getClass().toGenericString())); } private InternetAddressType convert(at.gv.zustellung.app2mzs.xsd.persondata.InternetAddressType address) { @@ -244,20 +250,22 @@ public class Mzs2MsgConverter { //------------ PERSONS -------------------- - public JAXBElement convert( + public JAXBElement convert( JAXBElement jaxbPerson) { var mzsPerson = jaxbPerson.getValue(); + //todo: move this to mzs Assert.isTrue(personIsPhysical(mzsPerson) || personIsCorporateBody(mzsPerson), "Person is neither a PhysicalPerson nor a CorporateBody."); - var msgPerson = (personIsPhysical(mzsPerson)) - ? convert((at.gv.zustellung.app2mzs.xsd.persondata.PhysicalPersonType) mzsPerson) - : convert((at.gv.zustellung.app2mzs.xsd.persondata.CorporateBodyType) mzsPerson); - - return personFactory.createPerson(msgPerson); - + if (personIsPhysical(mzsPerson)) { + var msgPerson = convert((at.gv.zustellung.app2mzs.xsd.persondata.PhysicalPersonType) mzsPerson); + return personFactory.createPhysicalPerson(msgPerson); + } else { + var msgPerson = convert((at.gv.zustellung.app2mzs.xsd.persondata.CorporateBodyType) mzsPerson); + return personFactory.createCorporateBody(msgPerson); + } } private boolean personIsPhysical(at.gv.zustellung.app2mzs.xsd.persondata.AbstractPersonType person) { -- cgit v1.2.3