diff options
author | Christof Rabensteiner <christof.rabensteiner@iaik.tugraz.at> | 2019-08-23 14:15:53 +0200 |
---|---|---|
committer | Christof Rabensteiner <christof.rabensteiner@iaik.tugraz.at> | 2019-08-23 15:17:14 +0200 |
commit | 7f4329d64ffc7007601f13cc398025e581570f4b (patch) | |
tree | 6b10bf3c8482dfe030b1d6efa2610655bd8e57ac | |
parent | 78aa4b019f64b6ba94df59e21efd4f9261bb070e (diff) | |
download | moa-zs-7f4329d64ffc7007601f13cc398025e581570f4b.tar.gz moa-zs-7f4329d64ffc7007601f13cc398025e581570f4b.tar.bz2 moa-zs-7f4329d64ffc7007601f13cc398025e581570f4b.zip |
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.
-rw-r--r-- | src/main/java/at/gv/egiz/moazs/scheme/Mzs2MsgConverter.java | 38 |
1 files changed, 23 insertions, 15 deletions
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<? extends AbstractAddressType> 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<AbstractPersonType> convert( + public JAXBElement<? extends AbstractPersonType> convert( JAXBElement<? extends at.gv.zustellung.app2mzs.xsd.persondata.AbstractPersonType> 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) { |