ph-fatturapa
Java library to easily read and write XML Schema compliant fatturaPA invoices.
Supported versions are:
- v1.2 (valid until 2020-12-31)
- v1.2.1 (valid from 2020-10-01)
It is licensed under Apache 2.0 license.
It requires at least Java 8 to be used.
Usage guide
All XML Schema files are converted using JAXB. For version 1.2 the generated types are prefixed with "FPA120", for version 1.2.1 they are prefixed with "FPA121" for easy differentiation.
Read and write fatturaPA invoices
Using the classes FatturaPA120Marshaller
and FatturaPA121Marshaller
you can read and write fatturaPA invoices. Class FatturaPA120Marshaller
handles version 1.2 and class FatturaPA121Marshaller
handles version 1.2.1.
Reading
Reading an existing fatturaPA 1.2 from an existing File is as easy as this:
FPA120FatturaElettronicaType aInvoice = new FatturaPA120Marshaller ().read (new File ("invoice.xml"));
if (aInvoice != null) {
// Reading was successful
} else {
// Error handling
}
There are several overloads of read
to read from different kind of sources.
Writing
Writing an existing FPA120FatturaElettronicaType
is also very simple:
FPA120FatturaElettronicaType aInvoice = ....;
if (new FatturaPA120Marshaller ().write (aInvoice, new File ("new-invoice.xml")).isSuccess ()) {
// Writing was successful
} else {
// Error handling
}
There are several overloads of write
to write from different kind of targets and getAs...
methods to convert the invoice to different formats.
By default a namespace context is present that uses the "p" prefix for the main element. If you want to change that, see the method setNamespaceContext
of the Marshaller classes.
Building from source
To build from source you need Apache Maven and Java 1.8 or later. Just run this on the commandline:
mvn clean install
Usage in an IDE
If you have build errors in your IDE, ensure that you once call mvn process-sources
on the project. This will create the Java classes representing the XML schema objects.
Afterwards you might need to manually add the following folders to your buildpath:
target/generated-sources/fatturapa120
target/generated-sources/fatturapa121
Maven usage
Add the following to your pom.xml to use this artifact, replacing x.y.z
with the real version number:
<dependency>
<groupId>com.helger</groupId>
<artifactId>ph-fatturapa</artifactId>
<version>x.y.z</version>
</dependency>
References
- Official fatturaPA format page - check the Italian version of the page; the English version is out of date
News and noteworthy
- v1.2.0 - 2021-05-02
- Updated to ph-commons 10.1
- v1.1.0 - 2021-03-21
- Updated to ph-commons 10
- v1.0.3 - 2020-09-17
- Updated to Jakarta JAXB 2.3.3
- v1.0.2 - 2020-08-28
- Using Java 8 date and time classes for JAXB created classes
- v1.0.1 - 2020-06-30
- Minor API extension
- v1.0.0 - 2020-06-17
- Initial version
My personal Coding Styleguide | On Twitter: @philiphelger | Kindly supported by YourKit Java Profiler