Comments (18)
@ralfhergert We'll get an example project posted soon - we just put one together to verify that Spring MVC 6 can deserialize an XML payload into a Product instance using jakarta.xml, and then the Java Client can serialize that to XML when that Product instance has a javax.xml annotation on it as well.
I definitely appreciate the ugliness and tedium of using both sets of annotations. We at least want to make sure that works fine via a working example, and then we're considering some options for how best to support jakarta.xml while still supporting Java 8 (which many customers still depend on).
from java-client-api.
@ralfhergert an update on this - our current thought is that we would change the Java Client to depend on jakarta.xml.bind
instead of javax.xml.bind
. The Java Client would still run fine on Java 8 as version 3 of jakarta.xml runs on Java 8. This will likely be done via a major release, as this would cause breaks for users currently on Java 8 that are happily using javax.xml.bind
.
Also, I noticed https://ralfhergert.github.io/beach-volleyball-scoring-sheet/ - very nice! I'm currently nursing a bad shoulder from playing volleyball, hoping to get back out there again soon.
from java-client-api.
It's certainly on our radar. Due to the presence of JAXB/Jakarta imports in public classes - JAXBHandle
being one - we'd need to do a major release, so Java Client 7. That branch you point to I believe verifies that Java 8 could still be the minimum required version while using the Jakarta APIs, so we could simply switch to Jakarta and continue development on 7.x with no need for a separate release.
from java-client-api.
Using Java 17, I created a SpringBoot 3 application that depends on Springframework 6 and Jakarta.xml.bind 4.
I created this project by starting with https://spring.io/guides/gs/spring-boot/ & https://github.com/spring-guides/gs-spring-boot.git.
Then I added a dependency on MarkLogic Client 6.2.2 and javax.xml.bind 2.3.1.
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation "javax.xml.bind:jaxb-api:2.3.1"
implementation "org.glassfish.jaxb:jaxb-runtime:2.3.2"
implementation "org.glassfish.jaxb:jaxb-core:2.3.0.1"
implementation "com.marklogic:marklogic-client-api:6.2.2"
implementation 'org.w3c:dom:2.3.0-jaxb-1.0.6'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
I continued by changing the default endpoint in HelloController.java, so that it would read a document from MarkLogic using a JAXBHandle, updating the resulting object, and writing the updated object as a new document.
package com.example.springboot;
import com.marklogic.client.DatabaseClient;
import com.marklogic.client.DatabaseClientFactory;
import com.marklogic.client.document.XMLDocumentManager;
import com.marklogic.client.io.JAXBHandle;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.annotation.XmlRootElement;
@RestController
public class HelloController {
@GetMapping("/")
public String index() throws JAXBException {
DatabaseClient client = DatabaseClientFactory.newClient(
"localhost", 8055, new DatabaseClientFactory.DigestAuthContext("admin", "admin"));
XMLDocumentManager XMLDocMgr = client.newXMLDocumentManager();
JAXBContext jaxbContext = JAXBContext.newInstance(Product.class);
@SuppressWarnings({ "rawtypes", "unchecked" })
JAXBHandle jaxbH = new JAXBHandle(jaxbContext);
XMLDocMgr.read("/product.xml", jaxbH);
System.out.println(jaxbH.toString());
((Product) jaxbH.get()).setName("Alex");
((Product) jaxbH.get()).setIndustry("Bookkeeping");
((Product) jaxbH.get()).setDescription("Librarian");
XMLDocMgr.write("/productAlex.xml", jaxbH);
client.release();
return "Greetings from Spring Boot!";
}
@XmlRootElement
static public class Product {
private String name;
private String industry;
private String description;
public Product() {
super();
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getIndustry() {
return industry;
}
public void setIndustry(String industry) {
this.industry = industry;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
}
}
All this works as expected when a request is sent to the endpoint. The original document (which I already had in the database) is read and printed to standard out, and a new document is created in the database.
Hopefully that helps with using the current client with SpringBoot 3.
from java-client-api.
Hi Bill, this issue here was written as link to https://help.marklogic.com/Tickets/Ticket/View/35838.
To put it simply javax.xml.bind:jaxb-api:2.3.1
is not Jakarta EE 10.
from java-client-api.
To put it simply javax.xml.bind:jaxb-api:2.3.1 is not Jakarta EE 10.
Yes, but that does not mean that you can't use it. You just have to add it as a dependency as I did above. For more information on using the older version of JAXB with EE 10, please see https://github.com/marklogic/java-client-api#including-jaxb-support
from java-client-api.
@ralfhergert What @BillFarber 's example verifies is that you can have a Spring Boot 3 / Spring 6 / Java EE 10 / Java 17+ application and still use the older javax libraries, as they won't conflict with the newer jakarta libraries. We are hoping that same approach will work for you as well.
from java-client-api.
Hi @BillFarber, could you add a rest-controller-method in your example which returns a ResponseEntity<Product>
?
That would be the point at which I'm struggling right now: it seems that spring-webmvc 6 cannot find an appropriate handler to map the JAXB2-annotated entity (javax.xml.*) into a character representation.
from java-client-api.
@ralfhergert Please try the project in the zip attached to this comment (note that there's not a root directory in the zip, so unzip it into a new project directory first). The README has instructions on how to test it out.
For the GET endpoint, I took the approach of using javax.xml and the Java Client to read an XML document from MarkLogic as a Product
instance. And then the controller method relies on Spring Boot 3 to deserialize that into a String. While that enforces schema validation per the Product
class, you could also just return the raw XML string from MarkLogic depending on your requirements.
from java-client-api.
The downside of course to the approach in the example project is this:
@XmlRootElement
@javax.xml.bind.annotation.XmlRootElement
public class Product
And of course, if you're having to annotate methods/fields because the default names generated by JAXB aren't acceptable, the above will get annoying very quickly.
from java-client-api.
Thank you, @rjrudin ! I will give it a try. I'm in vacation the next 2 weeks, so please don't mind if I don't reply rigth away.
from java-client-api.
@ralfhergert Did the above approach work for you? We do hope to shift to either a minimum version of Java 11 or 17 soon, but like many vendors, we have a significant number of customers still on Java 8.
from java-client-api.
Hi @rjrudin thanks for pinging. Yes, as far I can tell, the double annotation with jakata and javax does work in a sense that both the marklogic-client and springboot-3 can deal with the same POJOs. It is not a pretty solution, as the POJOs get very crowded for instance:
/**
* This class describes the state of a bulk ingest execution
*/
@XmlRootElement(name = "execution", namespace = "")
@javax.xml.bind.annotation.XmlRootElement(name = "execution", namespace = "")
@XmlAccessorType(XmlAccessType.FIELD)
@javax.xml.bind.annotation.XmlAccessorType(javax.xml.bind.annotation.XmlAccessType.FIELD)
public class BulkIngestExecution {
@XmlAttribute
@javax.xml.bind.annotation.XmlAttribute
private UUID id;
private TargetDb targetDb;
@XmlElement(name = "executionStatus")
@javax.xml.bind.annotation.XmlElement(name = "executionStatus")
private ExecutionStatus status = ExecutionStatus.NEW;
private String result;
private String resultDetails;
@XmlJavaTypeAdapter(GlobalDateTimeAdapterJakarta.class)
@javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter(GlobalDateTimeAdapter.class)
@JsonSerialize(using = GlobalDateTimeSerializer.class)
@JsonDeserialize(using = GlobalDateTimeDeserializer.class)
private GlobalDateTime lastChanged;
@XmlElementWrapper(name = "properties")
@javax.xml.bind.annotation.XmlElementWrapper(name = "properties")
@XmlElement(name = "property", type = Property.class)
@javax.xml.bind.annotation.XmlElement(name = "property", type = Property.class)
@JsonProperty
@JsonInclude(value= JsonInclude.Include.NON_EMPTY, content=JsonInclude.Include.NON_NULL)
private List<Property> properties;
[...]
And the solution comes with a price-tag:
- we need to double all our tests for verifying that we used the annotations correctly (JAXB-de/serialization-tests)
- we need to double all our adaptor-classes to provide Javax- and Jakarta-compatible versions of it, of course we need to tests for both
More code/tests means higher costs for maintainance/refactoring and longer build-cycles.
I do understand that you need to support your customers still using Java8. So maybe forking is a strategy here to provide both at the same time: one fork using javax and another one using jakarta?
from java-client-api.
@ralfhergert We're going to look soon into what a fork would entail - ideally, we can partition off all the javax-specific code into a small place and just have that be the one different thing across the two products.
from java-client-api.
Thanks @rjrudin! Wow that is great news! I'm looking forward to it.
Get well soon! Beach Volleyball is great fun and I always enjoy playing it, even tough I no longer participate in tournaments. :) (I made the scoring sheet as a simpler alternative to some overly complex sheets.)
from java-client-api.
Hi @rjrudin You created this feature-branch some time ago: https://github.com/marklogic/java-client-api/tree/feature/jakarta-xml
Do you also plan to provide it as a release version? How about a dual release strategy in which a javax and a jakarta version are released in parallel? What do you think?
from java-client-api.
Related Issues (20)
- Transfer Encoding has non-emtpy body when no result in returned through okhttp HOT 3
- op.sampleBy misses the 0 parameter overloaded method HOT 1
- Delete temporal documents via DMSDK HOT 2
- Specifi page length and startIndex for dataMOvementManager using newQueryBatcher HOT 3
- Upgrade to jackson-databind 2.14.0 when available HOT 2
- WriteBatcher does not write documents when total documents provided is less than 100 and without using withBatchSize HOT 1
- SparQL query throws unexpected error HOT 3
- Executing PatchHandle against non-existing Document does not throw an Exception HOT 5
- Incorrectly return empty query result HOT 3
- Support for Java 17? HOT 8
- Numbers returned by MarkLogic do not use scientific notation HOT 1
- Implementations of innerSerialize lack proper namespace HOT 11
- Feature Request: OptimisticLockingExecption HOT 7
- Remove "ML-Check-ML11-Headers" for ML11 java client api HOT 1
- Directory queries allow for invalid values of "depth" without throwing an error HOT 3
- Wrong timeout conversion in awaitCompletion HOT 4
- search:and-not-query is ignored in QueryBatcher HOT 6
- queryManager.uris does not honor additional-query in search options HOT 6
- Support for cts:annotation in cts:query? HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from java-client-api.