phax / ph-ubl

Java library for reading and writing UBL 2.0, 2.1, 2.2, 2.3 and 2.4 documents
Apache License 2.0
106 stars 40 forks source link

[ph-ubl20] The value of 'DocType' may not be null! #15

Closed osvalr closed 5 years ago

osvalr commented 6 years ago

I am trying to use UBL20WriterBuilder with a customized definition based on UBL like this way:

UBL20WriterBuilder<CustomDocumentType> ubl20Builder = new UBL20WriterBuilder<>(CustomDocumentType.class);

When trying to instantiate I get the following stacktrace:

java.lang.NullPointerException: The value of 'DocType' may not be null!
    at com.helger.commons.ValueEnforcer.notNull(ValueEnforcer.java:219)
    at com.helger.commons.ValueEnforcer.notNull(ValueEnforcer.java:199)
    at com.helger.jaxb.builder.AbstractJAXBBuilder.<init>(AbstractJAXBBuilder.java:49)
    at com.helger.jaxb.builder.AbstractWritingJAXBBuilder.<init>(AbstractWritingJAXBBuilder.java:71)
    at com.helger.jaxb.builder.JAXBWriterBuilder.<init>(JAXBWriterBuilder.java:65)
    at com.helger.ubl20.UBL20WriterBuilder.<init>(UBL20WriterBuilder.java:37)
    at com.helger.ubl20.UBL20WriterBuilder.<init>(UBL20WriterBuilder.java:48)
    at com.example.MainApplication.buildCustomDocument(MainApplication.java:224)

Is there no option here? I suppose it is failing due there is not similar document supported.

phax commented 6 years ago

I have never tried it with custom document types, and there it will most likely not be supported. You should use JAXBWriterBuilder with a custom IJAXBDocumentType since you are basically leaving the UBL arena and use "any other" XSD that just re-uses UBL document types.

In that case the best way is to come up with a custom Maven configuration that converts your XSD to Java code re-using the types from ph-ubl. See e.g. theph-ubltr subproject pom.xml (https://github.com/phax/ph-ubl/blob/master/ph-ubltr/pom.xml) that does exactly that. It's a quite tricky Maven configuration with plugins, bindings and catalogues referencing Maven artefacts.

hth

phax commented 6 years ago

Did you manage to progress here?

osvalr commented 6 years ago

Still I haven't tried yet just because I tried the marshaller from jaxb as easy-to-do for UBL-based documents. IMHO I will give a this on this but it sounds quite tricky.

FTR: I did something like the proposed here https://stackoverflow.com/a/1983172

It seems fair to me to close this, any other advance on this I will be posting in here

phax commented 6 years ago

This is what I do internally as well. Can you point me to the XSD you are using, so I can potentially help you

osvalr commented 6 years ago

Sure, see maindoc/UBLPE-SummaryDocuments-1.0.xsd included in this zip.

phax commented 6 years ago

That is the official Peru UBL version? I could create an "official" subproject if that helps....

I found https://github.com/FrameworkPeru/openinvoiceperudocs - is that official?

phax commented 6 years ago

I compared the XML Schemas and found out the following: