debitDetails = new ArrayList<>();
protected Contact contact = null;
+ /**
+ * Default constructor.
+ * Probably a bad idea but might be needed by jackson or similar
+ */
+ public TradeParty() {
+
+ }
+
+
/***
*
* @param name of the company
@@ -118,13 +129,11 @@ public class TradeParty implements IZUGFeRDExportableTradeParty {
for (int taxChildIndex = 0; taxChildIndex < taxChilds.getLength(); taxChildIndex++) {
if (taxChilds.item(taxChildIndex).getLocalName() != null) {
if ((taxChilds.item(taxChildIndex).getLocalName().equals("ID"))) {
- if (taxChilds.item(taxChildIndex).getAttributes().getNamedItem("schemeID")!=null) {
- if (taxChilds.item(taxChildIndex).getAttributes().getNamedItem("schemeID").getNodeValue().equals("VA"))
- {
+ if (taxChilds.item(taxChildIndex).getAttributes().getNamedItem("schemeID") != null) {
+ if (taxChilds.item(taxChildIndex).getAttributes().getNamedItem("schemeID").getNodeValue().equals("VA")) {
setVATID(taxChilds.item(taxChildIndex).getFirstChild().getNodeValue());
}
- if (taxChilds.item(taxChildIndex).getAttributes().getNamedItem("schemeID").getNodeValue().equals("FC"))
- {
+ if (taxChilds.item(taxChildIndex).getAttributes().getNamedItem("schemeID").getNodeValue().equals("FC")) {
setTaxID(taxChilds.item(taxChildIndex).getFirstChild().getNodeValue());
}
}
diff --git a/library/src/main/java/org/mustangproject/ZUGFeRD/IZUGFeRDExportableItem.java b/library/src/main/java/org/mustangproject/ZUGFeRD/IZUGFeRDExportableItem.java
index 65318300..9730df2c 100644
--- a/library/src/main/java/org/mustangproject/ZUGFeRD/IZUGFeRDExportableItem.java
+++ b/library/src/main/java/org/mustangproject/ZUGFeRD/IZUGFeRDExportableItem.java
@@ -26,11 +26,14 @@ package org.mustangproject.ZUGFeRD;
* @author jstaerk
* */
+import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
+import org.mustangproject.Item;
+
import java.math.BigDecimal;
import java.util.Date;
+@JsonDeserialize(as = Item.class)
public interface IZUGFeRDExportableItem extends IAbsoluteValueProvider{
-
IZUGFeRDExportableProduct getProduct();
/**
diff --git a/library/src/test/java/org/mustangproject/ZUGFeRD/DeSerializationTest.java b/library/src/test/java/org/mustangproject/ZUGFeRD/DeSerializationTest.java
new file mode 100644
index 00000000..0e9ea12d
--- /dev/null
+++ b/library/src/test/java/org/mustangproject/ZUGFeRD/DeSerializationTest.java
@@ -0,0 +1,53 @@
+
+/**
+ * *********************************************************************
+ *
+ * Copyright 2019 Jochen Staerk
+ *
+ * Use is subject to license terms.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0.
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * **********************************************************************
+ */
+package org.mustangproject.ZUGFeRD;
+
+import com.fasterxml.jackson.core.JsonParseException;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.JsonMappingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import junit.framework.TestCase;
+import org.assertj.core.util.Lists;
+import org.junit.FixMethodOrder;
+import org.junit.runners.MethodSorters;
+import org.mustangproject.*;
+
+import java.math.BigDecimal;
+import java.util.Date;
+
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+public class DeSerializationTest extends TestCase {
+ public void testJackson() throws JsonProcessingException {
+
+ ObjectMapper mapper = new ObjectMapper();
+ Invoice i = new Invoice().setDueDate(new Date()).setIssueDate(new Date()).setDeliveryDate(new Date()).setSender(new TradeParty("some org", "teststr", "55232", "teststadt", "DE").addTaxID("taxID")).setOwnVATID("DE0815").setRecipient(new TradeParty("Franz Müller", "teststr.12", "55232", "Entenhausen", "DE").addVATID("DE4711").setContact(new Contact("Franz Müller", "01779999999", "franz@mueller.de", "teststr. 12", "55232", "Entenhausen", "DE"))).setNumber("0185").addItem(new Item(new Product("Testprodukt", "", "C62", new BigDecimal(19)), new BigDecimal("1"), new BigDecimal(1.0)));
+ String jsonArray = mapper.writeValueAsString(i);
+
+ // [{"stringValue":"a","intValue":1,"booleanValue":true},
+ // {"stringValue":"bc","intValue":3,"booleanValue":false}]
+
+ Invoice fromJSON = mapper.readValue(jsonArray, Invoice.class);
+ assertEquals(fromJSON.getNumber(), i.getNumber());
+ assertEquals(fromJSON.getZFItems().length, i.getZFItems().length);
+
+ }
+}