Here is the situation.
When I use EclipseLink MOXy with Spring 3 MVC to generate JSON output it throws following exception when I try to set the json media type with following statement.
marshaller.setProperty(JAXBContextProperties.MEDIA_TYPE, "application/json");
javax.xml.bind.PropertyException: name: eclipselink.media-type value: application/json
at org.eclipse.persistence.jaxb.JAXBMarshaller.setProperty(JAXBMarshaller.java:520)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:176)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:436)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:424)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:790)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:669)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:574)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
I am using JAXBviews too to generate xml output for other services in the application. Here is the beans declaration in application-context.xml for the same.
<bean id="jaxbMarshaller" class="com.abc.restws.marshallers.ClasspathScanningJaxb2Marshaller">
<property name="basePackages" ref="jaxbBasePackages" />
</bean>
<bean id="jaxbMarshallingView" class="org.springframework.web.servlet.view.xml.MarshallingView">
<property name="marshaller" ref="jaxbMarshaller"/>
</bean>
<bean id="jaxbJsonMarshallingView" class="org.springframework.web.servlet.view.xml.MarshallingView">
<property name="contentType" value="application/json"/>
<property name="marshaller" ref="jaxbJsonMarshaller"/>
</bean>
What's the reason for this error? How can i fix this error? XML output is generated fine but for JSON it throws this exception. You can see in the exception details it's using correct JAXBMarshaller class too to set the json media type. Please advice.
"org.eclipse.persistence.jaxb.JAXBMarshaller.setProperty(JAXBMarshaller.java:520)"