|
Re: Marshalling attributes as node, why ? [message #521837 is a reply to message #521808] |
Thu, 18 March 2010 21:10 |
|
If you have the following the you should see properties attribute0 & attribute1 marshal as attributes. Can you share your model?
import javax.xml.bind.annotation.XmlAttribute;
public class Node {
private String attribute0;
private String attribute1;
@XmlAttribute
public String getAttribute0() {
return attribute0;
}
public void setAttribute0(String attribute0) {
this.attribute0 = attribute0;
}
@XmlAttribute
public String getAttribute1() {
return attribute1;
}
public void setAttribute1(String attribute1) {
this.attribute1 = attribute1;
}
}
-Blaise
|
|
|
Re: Marshalling attributes as node, why ? [message #521912 is a reply to message #521808] |
Fri, 19 March 2010 09:34 |
Nicola Messages: 4 Registered: July 2009 |
Junior Member |
|
|
Hi, I have the same issue, I'm using EclipseLink OSGI version 2.0.1.
I have tested with the model you proposed and a blank project, this is the Activator class:
public void start(BundleContext context) throws Exception
{
JAXBContext jaxbContext = null;
jaxbContext = JAXBContext.newInstance("my.models", new BundleProxyClassLoader(context.getBundle()));
Node n = new Node();
n.setAttribute0("mioatt0");
n.setAttribute1("mioatt1");
// Step 2 - Convert the Domain Model to XML
Marshaller marshaller = jaxbContext.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.marshal(new ObjectFactory().createNode(n), System.out);
}
I have found BundleProxyClassLoader somewhere in another user thread to let MOXy find ObjectFactory inside my models package.
This is the output of ss:
Framework is launched.
id State Bundle
0 ACTIVE org.eclipse.osgi_3.5.1.R35x_v20090827
Fragments=9
1 ACTIVE org.eclipse.persistence.core_2.0.1.v20100213-r6600
Fragments=2
2 RESOLVED org.eclipse.persistence.oracle_2.0.1.v20100213-r6600
Master=1
3 ACTIVE javax.xml_1.3.4.v200902170245
4 ACTIVE javax.activation_1.1.0.v200906290531
5 ACTIVE org.eclipse.persistence.moxy_2.0.1.v20100213-r6600
6 ACTIVE javax.persistence_2.0.0.v201002051058
7 ACTIVE javax.mail_1.4.0.v200905040518
8 ACTIVE provaxml_1.0.0.qualifier
9 RESOLVED org.eclipse.persistence.jpa.equinox.weaving_2.0.1.v20100213-r6600
Master=0
10 ACTIVE javax.resource_1.5.0.v200906010428
11 ACTIVE org.eclipse.persistence.asm_2.0.1.v20100213-r6600
12 ACTIVE javax.xml.stream_1.0.1.v201001131653
13 ACTIVE javax.jms_1.1.0.v200906010428
14 ACTIVE javax.transaction_1.1.0.v201002051055
15 ACTIVE org.eclipse.persistence.antlr_2.0.1.v20100213-r6600
16 ACTIVE javax.xml.bind_2.1.12.v200912160909
bundle 8 is my testbundle.
and this is the output:
osgi> <START>
org.eclipse.persistence.jaxb.JAXBContext
<?xml version="1.0" encoding="UTF-8"?>
<ns0:node xsi:type="node" xmlns:ns0="http://my.models" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<attribute0>mioatt0</attribute0>
<attribute1>mioatt1</attribute1>
</ns0:node>
<END>
If I use non OSGI version of EclipseLink MOXy the XML output is OK :-\
[Updated on: Fri, 19 March 2010 09:35] Report message to a moderator
|
|
|
|
Powered by
FUDForum. Page generated in 0.03989 seconds