Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » parse orm mapping in json format(How to configure rom.xml in json format)
parse orm mapping in json format [message #1229670] Fri, 10 January 2014 00:21 Go to next message
jason zhang is currently offline jason zhangFriend
Messages: 31
Registered: July 2009
Member
Hi,
I have a orm mapping file. It is in json format instead of xml format.
When I tried to parse it like this
	XMLContext context = new XMLContext(new XMLEntityMappingsMappingProject(XMLEntityMappingsReader.ECLIPSELINK_ORM_NAMESPACE,
				XMLEntityMappingsReader.ECLIPSELINK_ORM_XSD));
		org.eclipse.persistence.jaxb.JAXBContext ctx=new org.eclipse.persistence.jaxb.JAXBContext(context);
		JAXBUnmarshaller unmarshaller = ctx.createUnmarshaller();
		unmarshaller.setProperty("eclipselink.media-type", "application/json");
		return (XMLEntityMappings) unmarshaller.unmarshal(reader);


I got this error

javax.xml.bind.UnmarshalException
 - with linked exception:
[Exception [EclipseLink-25038] (Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5): org.eclipse.persistence.exceptions.XMLMarshalException
Exception Description: DOMPlatform is not supported with media type applicaion/json.]
	at org.eclipse.persistence.jaxb.JAXBUnmarshaller.handleXMLMarshalException(JAXBUnmarshaller.java:980)
	at org.eclipse.persistence.jaxb.JAXBUnmarshaller.unmarshal(JAXBUnmarshaller.java:189)
	at com.flexdms.flexims.jpa.eclipselink.MetaSourceBuilder.fromJson(MetaSourceBuilder.java:466)
	at com.flexdms.flexims.unit.jpa.eclipselink.TestMarshaller.testJsonUnmarshaller(TestMarshaller.java:27)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:606)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: Exception [EclipseLink-25038] (Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5): org.eclipse.persistence.exceptions.XMLMarshalException
Exception Description: DOMPlatform is not supported with media type applicaion/json.
	at org.eclipse.persistence.exceptions.XMLMarshalException.unsupportedMediaTypeForPlatform(XMLMarshalException.java:408)
	at org.eclipse.persistence.internal.oxm.record.DOMUnmarshaller.unmarshal(DOMUnmarshaller.java:268)
	at org.eclipse.persistence.oxm.XMLUnmarshaller.unmarshal(XMLUnmarshaller.java:435)
	at org.eclipse.persistence.jaxb.JAXBUnmarshaller.unmarshal(JAXBUnmarshaller.java:176)
	... 25 more



I use json since the mapping file will be generated by javascript. I have no problem to marshaller the mapping as json.

Any idea how to workaround this?

Really appreciated.

thanks
Re: parse orm mapping in json format [message #1229942 is a reply to message #1229670] Fri, 10 January 2014 15:59 Go to previous messageGo to next message
Blaise Doughan is currently offline Blaise DoughanFriend
Messages: 163
Registered: July 2009
Senior Member

Hi Jason,

Try changing your code to do the following:
XMLEntityMappingsMappingProject project = new XMLEntityMappingsMappingProject(XMLEntityMappingsReader.ECLIPSELINK_ORM_NAMESPACE, XMLEntityMappingsReader.ECLIPSELINK_ORM_XSD);
project.getDatasourceLogin().setDatasourcePlatform(new SAXPlatform());
XMLContext context = new XMLContext(project);

-Blaise
Re: parse orm mapping in json format [message #1229964 is a reply to message #1229942] Fri, 10 January 2014 17:13 Go to previous message
jason zhang is currently offline jason zhangFriend
Messages: 31
Registered: July 2009
Member
Works!
Really appreciated.

-jason
Previous Topic:Setter Methods not getting invoked with eclispe link
Next Topic:ClassCastException while using Criteria API with @ElementCollection
Goto Forum:
  


Current Time: Wed Feb 05 04:54:59 GMT 2025

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

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

Back to the top