JAX-RS databinding support for JiBX
-----------------------------------

                 Key: CXF-4245
                 URL: https://issues.apache.org/jira/browse/CXF-4245
             Project: CXF
          Issue Type: Bug
          Components: JAXB Databinding
    Affects Versions: 2.6
         Environment: All Environments
            Reporter: Don Corley
             Fix For: 2.6.1


Dan,
Thanks again for writing the databinding components for JiBX.
Unfortunately, the JAX-RS component calls empty methods when I try to use this 
databinding component.
This seems to fix the problem:
---start patch
Index: rt/databinding/jibx/src/main/java/org/apache/cxf/jibx/JibxDataWriter.java
===================================================================
--- rt/databinding/jibx/src/main/java/org/apache/cxf/jibx/JibxDataWriter.java   
(revision 1327050)
+++ rt/databinding/jibx/src/main/java/org/apache/cxf/jibx/JibxDataWriter.java   
(working copy)
@@ -40,6 +40,15 @@
 public class JibxDataWriter implements DataWriter<XMLStreamWriter> {
 
     public void write(Object obj, XMLStreamWriter output) {
+        try {
+            IBindingFactory factory = 
BindingDirectory.getFactory(obj.getClass());
+            IMarshallingContext ctx = getMarshallingContext(obj);
+            StAXWriter writer = new StAXWriter(factory.getNamespaces(), 
output);
+            ctx.setXmlWriter(writer);
+            ((IMarshallable)obj).marshal(ctx);
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
     }
 
     public void write(Object obj, MessagePartInfo part, XMLStreamWriter 
output) {
Index: rt/databinding/jibx/src/main/java/org/apache/cxf/jibx/JibxDataReader.java
===================================================================
--- rt/databinding/jibx/src/main/java/org/apache/cxf/jibx/JibxDataReader.java   
(revision 1327050)
+++ rt/databinding/jibx/src/main/java/org/apache/cxf/jibx/JibxDataReader.java   
(working copy)
@@ -62,7 +62,12 @@
     }
 
     public Object read(QName elementQName, XMLStreamReader input, Class<?> 
type) {
-        throw new UnsupportedOperationException("Not Implemented");
+        try {
+            UnmarshallingContext ctx = getUnmarshallingContext(input, type);
+            return ctx.unmarshalElement(type);
+        } catch (JiBXException e) {
+            throw new RuntimeException(e);
+        }
     }
 
     public void setAttachments(Collection<Attachment> attachments) {
--- end patch
I have a sample project at if you want to see a working configuration:
https://github.com/jibx/maven-plugin/tree/master/examples/cxf-jaxrs

Remember to shutdown karaf after install, before start to avoid a karaf wiring 
bug.

Thanks!
Don

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Reply via email to