moved json serialisation for freemarker template to individual class

improved GSON handling
updated GSON to 2.7
This commit is contained in:
jomu
2016-06-22 15:23:52 +00:00
parent fbe9e99765
commit 8550bf408c
24 changed files with 475 additions and 117 deletions

View File

@ -27,7 +27,7 @@ public class DefaultTableRowTest {
" }";
TableRow tableRow = GsonUtil.getGsonInstance().fromJson(jsonString, TableRow.class);
TableRow tableRow = GsonUtil.getInstance().fromJson(jsonString, TableRow.class);
assertNotNull ("tableRowObject", tableRow);
assertEquals ("column count", 2, tableRow.getColumnCount());
assertFalse ("isList", tableRow.isList());

View File

@ -0,0 +1,24 @@
package de.muehlencord.shared.pdf;
import org.junit.Test;
import static org.junit.Assert.*;
/**
*
* @author joern.muehlencord
*/
public class PDFFontTest {
public PDFFontTest() {
}
@Test
public void testTemplateSerialisation() {
PDFFont font = new PDFFont("Test", 12, 0);
String gsonString = GsonUtil.getInstance().toJson(font);
String templateString = font.getTemplateJsonString();
System.out.println(templateString);
assertEquals(gsonString, templateString);
}
}

View File

@ -0,0 +1,26 @@
package de.muehlencord.shared.pdf;
import java.io.File;
import java.io.IOException;
import org.junit.Test;
/**
*
* @author joern.muehlencord
*/
public class PDFImageContentTest {
public PDFImageContentTest() {
}
@Test
public void testImage() throws IOException {
PDFDocument doc = new PDFDocument(PDFPaperSize.A4);
PDFImageContent logoContent = new PDFImageContent(doc, 400F, 700F, 0.6F, new File("c:/temp/logo-verkehrsverein-hoevelh.jpg"));
System.out.println(GsonUtil.getInstance().toJson(logoContent));
System.out.println(GsonUtil.getInstance().toJson(logoContent));
}
}

View File

@ -0,0 +1,39 @@
package de.muehlencord.shared.pdf;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import org.junit.Test;
/**
*
* @author joern.muehlencord
*/
public class PDFTextContentTest {
@Test
public void testSomeMethod() {
PDFDocument doc = new PDFDocument(PDFPaperSize.A4);
PDFTextContent informationContent = new PDFTextContent(doc, 400F, 662F);
informationContent.addLine("Anzeigenabrechnung", "bold");
informationContent.addLine("Veronika Mühlencord", "helv12");
informationContent.addLine("Telefon: 05257/940154", "helv12");
informationContent.addLine("Telefax: 05257/940156", "helv12");
informationContent.addLine();
informationContent.addLine("Hövelhof, den ${invoice.invoiceDate?date}", "bold");
doc.addContent(informationContent);
// System.out.println (informationContent.getTemplateJsonString());
// System.out.println ("*****");
// System.out.println (GsonUtil.getGsonInstance().toJson(informationContent));
System.out.println("*****");
Gson gson = new GsonBuilder()
.registerTypeAdapterFactory(new PDFImageContentTypeAdapterFactory())
.setPrettyPrinting()
.excludeFieldsWithoutExposeAnnotation()
.create();
System.out.println(gson.toJson(informationContent, PDFTextContent.class));
}
}

View File

@ -18,7 +18,7 @@ public class TextTest {
+ "\"text\": \"Rechnungs-Nr.:\"\n"
+ "}";
TextElement text = GsonUtil.getGsonInstance().fromJson(jsonString, TextElement.class);
TextElement text = GsonUtil.getInstance().fromJson(jsonString, TextElement.class);
assertNotNull ("text object", text);
assertEquals ("text value", "Rechnungs-Nr.:", text.getText());