2012-05-04 27 views
0

私は、RESTのジャージ実装に基づいたプロジェクトに取り組んでいます。私は、永続性のためにJPAを使用しています.DIOのためのIoCをスプリングしています。今、JAXB(MOXy)でマーシャルする必要があるオブジェクトがあります。あなたが助けてくださいことができれば、私のクラスはfolling yet.The this tutoは、私は物事が作業を取得しようとしたが、残念ながら、私は成功していない:EclipseLinkは例外をスローしますか?

ルートクラッセ:

package com.persistent.entity; 

import java.util.HashMap; 
import java.util.Map; 

import javax.xml.bind.annotation.XmlAccessType; 
import javax.xml.bind.annotation.XmlAccessorType; 
import javax.xml.bind.annotation.XmlRootElement; 
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; 

@XmlAccessorType(XmlAccessType.NONE) 
@XmlRootElement 
public class Bar { 
    private Map<String,String> mapbar; 

    public Bar() { 

    } 

    public Bar(Map<String,String> map){ 
     this.mapbar = map; 
    } 

    @XmlJavaTypeAdapter(MapAdapter.class) 
    public Map<String, String> getMapbar() { 
     return mapbar; 
    } 

    public void setMapbar(Map<String, String> map) { 
     this.mapbar = map; 
    } 
} 

MapAdapterクラス:

​​

AdaptedMapクラス:

package com.persistent.entity; 

import javax.xml.bind.annotation.XmlAnyElement; 

//import org.w3c.dom.Document; 

public class AdaptedMap { 

    private Object value; 

    @XmlAnyElement 
    public Object getValue() { 
     return value; 
    } 

    public void setValue(Object value) { 
     this.value = value; 
    }  
} 

と、最終的には、リソースクラス:Tomcat上でこれを実行した後

package com.persistent.rest; 

import java.util.ArrayList; 
import java.util.HashMap; 
import java.util.List; 
import java.util.Map; 

import javax.ws.rs.DefaultValue; 
import javax.ws.rs.GET; 
import javax.ws.rs.Path; 
import javax.ws.rs.Produces; 
import javax.ws.rs.QueryParam; 
import javax.ws.rs.core.MediaType; 
import javax.ws.rs.core.Response; 
import javax.xml.bind.JAXBContext; 
import javax.xml.bind.Marshaller; 

import org.springframework.beans.factory.annotation.Autowired; 
import org.springframework.context.annotation.Scope; 
import org.springframework.stereotype.Component; 

import com.persistent.entity.Bar; 
import com.persistent.entity.BarList; 
import com.persistent.entity.Pie; 
import com.persistent.entity.Vente; 
import com.persistent.entity.VentesList; 
import com.persistent.entity.PieList; 
import com.persistent.service.VenteService; 
import com.sun.jersey.api.json.JSONWithPadding; 

// The Java class will be hosted at the URI path "/myresource" 
@Path("/myresource") 
@Component 
@Scope("request") 
public class MyResource { 

    @Autowired 
    VenteService venteService; 


    @GET 
    @Produces("application/x-javascript") 

    public JSONWithPadding getBarService(@QueryParam("callback") String callback){ 
     int i; 

     VentesList ventes = venteService.getAll(); 
     Map<String,String> hmBar = new HashMap<String,String>(); 

    for (i=0;i<ventes.getsimpleVentes().size();i++){ 
hmBar.put(ventes.getsimpleVentes().get(i).getProjet(),String.valueOf(
    ventes.getsimpleVentes().get(i).getNbrRsrv())); 

} 

    Bar ba = new Bar(hmBar); 
    return new JSONWithPadding(ba,callback); 
    } 
} 

私はこの例外を取得:

GRAVE: "Servlet.service()" pour la servlet Jersey Spring Web Application a généré une exception 
java.io.IOException: Error marshalling JAXB object of type "class com.persistent.entity.Bar". 
    at com.sun.jersey.core.provider.jaxb.AbstractRootElementProvider.writeTo(AbstractRootElementProvider.java:145) 
    at com.sun.jersey.spi.container.ContainerResponse.write(ContainerResponse.java:254) 
    at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:578) 
    at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:502) 
    at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:493) 
    at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:308) 
    at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:314) 
    at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:239) 
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) 
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) 
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) 
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) 
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) 
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) 
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) 
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298) 
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859) 
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588) 
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489) 
    at java.lang.Thread.run(Thread.java:619) 
Caused by: javax.xml.bind.MarshalException 
- with linked exception: 
[Exception [EclipseLink-25003] (Eclipse Persistence Services - 2.3.1.v20111018-r10243): org.eclipse.persistence.exceptions.XMLMarshalException 
Exception Description: An error occurred marshalling the object 
Internal Exception: Exception [EclipseLink-3001] (Eclipse Persistence Services - 2.3.1.v20111018-r10243): org.eclipse.persistence.exceptions.ConversionException 
Exception Description: The object [{Dyar Al Baydae=6, TEST=8, test=5, Dyar Al Bahja=20, Dyar Al Mansour=87}], of class [class java.util.HashMap], could not be converted to [class com.persistent.entity.AdaptedMap].] 
    at org.eclipse.persistence.jaxb.JAXBMarshaller.marshal(JAXBMarshaller.java:326) 
    at com.sun.jersey.core.provider.jaxb.AbstractRootElementProvider.writeTo(AbstractRootElementProvider.java:167) 
    at com.sun.jersey.core.provider.jaxb.AbstractRootElementProvider.writeTo(AbstractRootElementProvider.java:143) 
    ... 19 more 

答えて

0

私は私の他の解決策を見つけました問題は、ソリューションの投稿に基づいてhere ...それは私のために働いて、私は最高のソリューションは、HashMap型のオブジェクトのマッピングに最適だと思います。

関連する問題