Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Got PropertyException when using MOXy
Got PropertyException when using MOXy [message #1234708] Wed, 22 January 2014 16:33 Go to next message
Paul G is currently offline Paul G
Messages: 1
Registered: January 2014
Junior Member
Hey Forum!
I'm trying to use EclipseLink MOXy to marshal some models into XML. Therefor I would like to use ObjectGraphs to have a custom and different output of what is serialized into xml.

But when I try to implement the good examples of Blaise Doughan's blog (title: MOXy's Object Graphs - Input/Output Partial Models to XML & JSON) with Maven, I got following exception:
javax.xml.bind.PropertyException: name: eclipselink.object-graph value: contact info


Thats the used pom.xml:
<project xmlns="..." xmlns:xsi="..."
  xsi:schemaLocation="... ...">
  <modelVersion>4.0.0</modelVersion>

  <groupId>main</groupId>
  <artifactId>eclipselink_test</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>eclipselink_test</name>
  <url>link-to-maven</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
	<dependency>
		<groupId>org.eclipse.persistence</groupId>
		<artifactId>org.eclipse.persistence.moxy</artifactId>
		<version>2.5.1</version>
	</dependency>
    <dependency>
		<groupId>javax.xml.bind</groupId>
		<artifactId>jaxb-api</artifactId>
		<version>2.2.11</version>
	</dependency>
  </dependencies>
</project>


This is the model (Model.java):
package main.eclipselink_test;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;

import org.eclipse.persistence.oxm.annotations.XmlNamedAttributeNode;
import org.eclipse.persistence.oxm.annotations.XmlNamedObjectGraph;

@XmlNamedObjectGraph(
	    name="contact info",
	    attributeNodes={
	        @XmlNamedAttributeNode("name")
	    })

@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class Model {

	public Model() {
	}
	
	public Model(int id, String name) {
		this.id = id;
		this.name = name;
	}
	
    @XmlAttribute
    private int id;
 
    @XmlAttribute
    private String name;
 
}


Thats the Application (App.java):
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;

import org.eclipse.persistence.jaxb.MarshallerProperties;

public class App 
{
    public static void main( String[] args ) throws JAXBException
    {
    	JAXBContext jc = JAXBContext.newInstance(Model.class);
        
    	Model model = new Model(0, "testing");
         
        // Output XML
        Marshaller marshaller = jc.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        marshaller.marshal(model, System.out);
         
        // Output XML - Based on Object Graph
        marshaller.setProperty(MarshallerProperties.OBJECT_GRAPH, "contact info");
        marshaller.marshal(model, System.out);
    }
}



As you may see, I get the error message in App.java:
Exception in thread "main" javax.xml.bind.PropertyException: name: eclipselink.object-graph value: contact info
	at javax.xml.bind.helpers.AbstractMarshallerImpl.setProperty(Unknown Source)
	at com.sun.xml.internal.bind.v2.runtime.MarshallerImpl.setProperty(Unknown Source)
	at main.eclipselink_test.App.main(App.java:28)


(Sorry for the masses of code. I don't have the permission to post links.)

Does anybody have some suggestions what went wrong? Thanks!
Re: Got PropertyException when using MOXy [message #1235094 is a reply to message #1234708] Thu, 23 January 2014 15:07 Go to previous messageGo to next message
Matt MacIvor is currently offline Matt MacIvor
Messages: 14
Registered: July 2009
Junior Member
Hi Paul,

The problem here is that you're not picking up the EclipseLink MOXy JAXB implementation. The class com.sun.xml.internal.bind.v2.runtime.MarshallerImpl if from the JAXB reference implementation included in the JDK.

In order to use the MOXy implementation, you will need to include a jaxb.properties file in the package with your domain classes.

The jaxb.properties file should contain:
javax.xml.bind.context.factory=org.eclipse.persistence.jaxb.JAXBContextFactory

This should trigger the EclipseLink implementation to be used instead of the RI.

I hope this helps

-Matt

[Updated on: Thu, 23 January 2014 15:08]

Report message to a moderator

Re: Got PropertyException when using MOXy [message #1235125 is a reply to message #1234708] Thu, 23 January 2014 16:18 Go to previous message
Blaise Doughan is currently offline Blaise Doughan
Messages: 163
Registered: July 2009
Senior Member

Hi Paul,

Here is a link to a Maven project I have on GitHub that you could use as a model:
- https://github.com/bdoughan/blog20110322

You need to make sure the jaxb.properties file is in the following location:
src/main/resources/main/eclipselink_test/

-Blaise
Previous Topic:Performance Question - eclipselink.jdbc.cache-statements
Next Topic:Add entities programmatically
Goto Forum:
  


Current Time: Sat Sep 20 20:15:22 GMT 2014

Powered by FUDForum. Page generated in 0.02762 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software