phax / ph-ubl

Java library for reading and writing UBL 2.0, 2.1, 2.2, 2.3 and 2.4 (CS01) documents

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support for json

Penait1 opened this issue · comments

Are there any plans for json support? Or will it be xml only for now. Just wondering since I really like the library but it would be useful to have support for json aswell.

+1, especially useful when communicating with Javascript-based systems

Okay, noted. Are you aware of any tool support to create the necessary stubs?
What do you exactly expect with the JSON? Reading and Writing is pertty obvious, but is there a JSON Schema like representation for validation?
Anyone has an implementation hint for me, except for going with the existing JAXB annotations?

Notes to myself:
Specs: http://docs.oasis-open.org/ubl/UBL-2.1-JSON/v1.0/UBL-2.1-JSON-v1.0.html
Seems like there is no binding for 2.0 and 2.2 (yet)

As for my expectations of the JSON support, I'd say reading and writing would be the main focus in order to support non-XML supporting clients. Since PH-UBL validates the Java objects, AFAIK, validation could still be performed by the XSD's used currently.

Would simple JSON serializing suffice to map the data directly on the JAXB annotated classes?

Excuse me if my understanding of this library is insufficient to provide a useful answer.

commented

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Hello @phax,
Is there any possibility/way to use this library in the REST(JSON) based API framework?
The library is too good but I am a bit confused about JSON management in the library.

I am trying to make a Spring Boot-based application that will accept JSON(for now) Invoice/CN/DN/etc. and serialize that data to related Document and validate it and store it into the database.

Can you please help me to understand, how to integrate and use the library in the Spring boot application?

This library does NOT support the creation of JSON, because it is purely working on the JAXB objects and is hence limited to XML.
I think the JSON binding proposed at http://docs.oasis-open.org/ubl/UBL-2.3-JSON/v1.0/UBL-2.3-JSON-v1.0.html is ugly and I am not aware of any tool that performs these modifications on the fly.
Until that time I suggest you stick with XML - sorry

Thanks, @phax for the quick response.
The main issue is how can I receive XML in API in an application?
What is the way to accept UBL XML files in API requests? (As its structure now allowed in POST request(JAXRS/JAXB))
As of now, file upload is the only way. Upload XML file, write it to file system then pass it to UBLReader, after process delete file.
Please correct me if I am wrong.

I am confused about what you are writing.
You should easily be able to process UBL XML documents per POST with JAXB/JAXRS. Try using the type org.w3c.Document as the parameter to receive arbitrary XML payloads - if not please create a separate ticket with more context.
In general JAXRS should be totally content agnostic and take everything...

I have tried to send sample UBL 2.1 Invoice as a JAXRS with application/xml as a request/response type and org.w3c.dom.Document as parameter but it says 400-Bad Request
I am using Spring Boot.
Following error on Spring console:

Resolved [org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot deserialize instance of `org.w3c.dom.Node` out of START_OBJECT token; nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `org.w3c.dom.Node` out of START_OBJECT token
 at [Source: (PushbackInputStream); line: 2, column: 1]]

As I am not using JAXRS I can only provide you to official sources and not personal experience. Try e.g.

hth

Thanks for the details @phax
Will figure it out and try to have it in working condition.

@kurbhatt yes please do so. If not, please create a new issue - it is kind of off-topic in this one

I still don't think JSON really adds value here - it just adds complexity and requires transformations etc. XML is mature, well understood and has good tooling support - I will not add JSON support.