Skip to content

Latest commit

 

History

History
75 lines (51 loc) · 2.38 KB

File metadata and controls

75 lines (51 loc) · 2.38 KB

Sonarcloud Status Renovate enabled Maven Central

KSeF FA Java model

Model parser and validator for XML FA(2) KSeF structure.

Sample

Parse and validate FA(2) to Java model

FakturaSerializer serializer = new FakturaSerializer();
Faktura invoice = serializer.fromFile(new File("src/test/resources/fa.xml"), true);

Serialize model to XML (without validation)

FakturaSerializer fakturaSerializer = new FakturaSerializer();

Faktura invoice = fakturaSerializer.create();

Faktura.Podmiot1 podmiot1 = new Faktura.Podmiot1();
TAdres address = new TAdres();
address.setAdresL1("ul. Kolejowa 123");
address.setAdresL2("05-092 Łomianki");

podmiot1.setAdres(address);
invoice.setPodmiot1(podmiot1);

val str = fakturaSerializer.toString(invoice, false);

System.out.println(str);

Validate

val errors = new LinkedList<SAXParseException>();
val features = Set.of(new XMLValidator.SchemaFactoryFeature(XMLConstants.FEATURE_SECURE_PROCESSING, false));
// We need disable secure processing because the schema has restrictions to more than 1000 elements in a sequence
// which is completely ridiculous, but what we can do...

URL url = new URL("http://crd.gov.pl/wzor/2023/06/29/12648/schemat.xsd");
val schema = new StreamSource(url.openStream());
val result = XMLValidator.validate(new FileReader("src/test/resources/fa.xml"), schema, errors, features);

How to use with maven

Stable project attracts are available in Maven Central, just add dependency to your project:

<dependency>
    <groupId>io.alapierre.ksef.fa</groupId>
    <artifactId>ksef-fa-xml-model</artifactId>
    <version>3.0.0</version>
</dependency>

Another connected GitGub Repositories

Build Requirements

The project can be built on JDK17+.

Building the API client library requires:

  1. Java 17+
  2. Maven