-
Notifications
You must be signed in to change notification settings - Fork 18
feat: Control the RDF output format manually #277
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
@jadelkhoury need your help here. I just tested this PR on both refimpl and lyo-samples (against two live Jazz servers, which is relevant because this PR was trying to fix an issue for DNG). lyo-samples build went just fine: https://github.com/OSLC/lyo-samples/actions/runs/4703021261/jobs/8341007496 But the refimpl fails in https://github.com/oslc-op/refimpl/actions/runs/4703012037/jobs/8340986025#step:7:224 due to a bunch of class-not-found errors: There is no way this PR introduces this problem. Could you please check if this should be happening and where the fix is needed? |
1c84cfd to
fba9e1d
Compare
|
Scratch that, I just realized this branch has not been rebased for quite a while and Refimpl test against The sample code for But hey, it was a good test of my new semi-automatic PR testing flow! |
3e44a71 to
14fee00
Compare
dddd698 to
fae096f
Compare
fae096f to
98fd159
Compare
|
While I didn't see any breaking effect from the PR (labelling Breaking anyway, in case someone depends on this, cf. Hyrum's law), let's keep it until Lyo 6.0. I think we can aim for 6.0 release around Christmas because Jena plans to drop JDK 11 support in the fall and we will likely have to catch up before 2024. |
|
Additionally, I think it would be good to add a switch (JVM property, potentially) to control pretty/fast output format. E.g. we could use |
9b1d7ba to
60946b8
Compare
60946b8 to
94223a7
Compare
4ef534e to
51cb26d
Compare
b2cfc91 to
3a3f805
Compare
a82bdb6 to
91a11f8
Compare
91a11f8 to
1906c43
Compare
Signed-off-by: Andrew Berezovskyi <andriib@kth.se>
b7fe205 to
1698fa6
Compare
|
@oslc-bot /test-all |
# Conflicts: # core/oslc4j-jena-provider/src/main/java/org/eclipse/lyo/oslc4j/provider/jena/AbstractOslcRdfXmlProvider.java
Signed-off-by: Andrew Berezovskyi <andriib@kth.se>
|
@oslc-bot /test-all |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds manual control over RDF output format by mapping RDF serialization languages to specific Jena RDFFormat types. The key change maps regular RDF/XML to RDFXML_PLAIN (not abbreviated) unless the abbreviated format is explicitly requested, addressing compatibility issues with IBM DOORS.
Key changes:
- Introduces a
resolveFormat()method to map serialization language strings to specific RDFFormat constants - Modifies the write path to use
RDFDataMgr.write()with explicit formats for non-abbreviated serializations - Preserves the existing abbreviated RDF/XML behavior through conditional branching
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if (writer instanceof RdfXmlAbbreviatedWriter) { | ||
| writer.write(model, | ||
| outputStream, | ||
| null); | ||
| } else { | ||
| RDFDataMgr.write(outputStream, model, resolveFormat(serializationLanguage)); | ||
| } |
Copilot
AI
Dec 13, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The indentation of this code block is inconsistent with the rest of the file. The if-else block should use consistent indentation matching the surrounding code style (typically 2 or 4 spaces per level).
| if (writer instanceof RdfXmlAbbreviatedWriter) { | |
| writer.write(model, | |
| outputStream, | |
| null); | |
| } else { | |
| RDFDataMgr.write(outputStream, model, resolveFormat(serializationLanguage)); | |
| } | |
| if (writer instanceof RdfXmlAbbreviatedWriter) { | |
| writer.write(model, | |
| outputStream, | |
| null); | |
| } else { | |
| RDFDataMgr.write(outputStream, model, resolveFormat(serializationLanguage)); | |
| } |
| private RDFFormat resolveFormat(String serializationLanguage) { | ||
| switch (serializationLanguage) { | ||
| case RDFLanguages.strLangRDFXML: | ||
| return RDFFormat.RDFXML_PLAIN; | ||
| case RDFLanguages.strLangTurtle: | ||
| return RDFFormat.TURTLE_PRETTY; | ||
| case RDFLanguages.strLangNTriples: | ||
| return RDFFormat.NTRIPLES_UTF8; | ||
| case RDFLanguages.strLangJSONLD: | ||
| return RDFFormat.JSONLD; | ||
| default: | ||
| throw new IllegalArgumentException(); | ||
| } | ||
| } |
Copilot
AI
Dec 13, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The indentation of this method is inconsistent with the rest of the file. The method body and switch statement should use consistent indentation matching the surrounding code style (typically 2 or 4 spaces per level).
| private RDFFormat resolveFormat(String serializationLanguage) { | |
| switch (serializationLanguage) { | |
| case RDFLanguages.strLangRDFXML: | |
| return RDFFormat.RDFXML_PLAIN; | |
| case RDFLanguages.strLangTurtle: | |
| return RDFFormat.TURTLE_PRETTY; | |
| case RDFLanguages.strLangNTriples: | |
| return RDFFormat.NTRIPLES_UTF8; | |
| case RDFLanguages.strLangJSONLD: | |
| return RDFFormat.JSONLD; | |
| default: | |
| throw new IllegalArgumentException(); | |
| } | |
| } | |
| private RDFFormat resolveFormat(String serializationLanguage) { | |
| switch (serializationLanguage) { | |
| case RDFLanguages.strLangRDFXML: | |
| return RDFFormat.RDFXML_PLAIN; | |
| case RDFLanguages.strLangTurtle: | |
| return RDFFormat.TURTLE_PRETTY; | |
| case RDFLanguages.strLangNTriples: | |
| return RDFFormat.NTRIPLES_UTF8; | |
| case RDFLanguages.strLangJSONLD: | |
| return RDFFormat.JSONLD; | |
| default: | |
| throw new IllegalArgumentException(); | |
| } | |
| } |
| outputStream, | ||
| null); | ||
| } else { | ||
| RDFDataMgr.write(outputStream, model, resolveFormat(serializationLanguage)); |
Copilot
AI
Dec 13, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When using RDFDataMgr.write() with RDFXML_PLAIN format, Jena may write its own XML declaration. Combined with the manual XML declaration written at lines 151-152 (for XML formats), this could result in duplicate XML declarations in the output. Consider either removing the manual XML declaration for non-abbreviated cases that use RDFDataMgr.write(), or configuring RDFDataMgr to suppress its XML declaration.
| case RDFLanguages.strLangJSONLD: | ||
| return RDFFormat.JSONLD; | ||
| default: | ||
| throw new IllegalArgumentException(); |
Copilot
AI
Dec 13, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default case throws an IllegalArgumentException with no error message. This makes it difficult to debug when an unsupported serialization language is passed. Consider adding a descriptive error message that includes the unsupported serialization language value to help with troubleshooting.
| throw new IllegalArgumentException(); | |
| throw new IllegalArgumentException("Unsupported serialization language: " + serializationLanguage); |
|
@oslc-bot /test-all |
|
In the current Lyo code, this should be enough to get things working with most Jazz tools, e.g. RRC: We will hold this patch until we are sure that the new approach still works with abbrev-dependent systems like Jazz. |

Description
Map RDF language to an exact format needed by https://jena.apache.org/documentation/io/rdf-output.html. This PR maps regular XML/RDF to
RDFXML_PLAIN, which is NOT rdf/xml-ABBREV, unless ABBREV is chosen specifically:https://github.com/eclipse/lyo/blob/b-jena-format-spec/core/oslc4j-jena-provider/src/main/java/org/eclipse/lyo/oslc4j/provider/jena/AbstractOslcRdfXmlProvider.java#L152-L158
Potentially, allow for more RDF/XML config as per https://jena.apache.org/documentation/io/rdfxml_howto.html
Checklist
Issues
https://forum.open-services.net/t/doors-lyo-incompatibility/631/5