IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Services Web Java Discussion :

[Hibernate, REST Jersey] Problème dans la transformation des données en JSON


Sujet :

Services Web Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Inscrit en
    Mars 2012
    Messages
    165
    Détails du profil
    Informations forums :
    Inscription : Mars 2012
    Messages : 165
    Par défaut [Hibernate, REST Jersey] Problème dans la transformation des données en JSON
    Bonjour,

    Je travaille sur une app web dont je voudrais afficher mes données sous format JSON. pour ça, je travaille avec Hibernate et Jersey.

    Voilà ma classe qui sert au contrôleur :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    @Path("/Country")
    public class CountryResource {
     
        // The @Context annotation allows us to have certain contextual objects
        // injected into this class.
        // UriInfo object allows us to get URI information (no kidding).
        @Context
        UriInfo uriInfo;
     
        // Another "injected" object. This allows us to use the information that's
        // part of any incoming request.
        // We could, for example, get header information, or the requestor's address.
        @Context
        Request request;
     
        // Basic "is the service running" test
        @GET
        @Produces(MediaType.TEXT_PLAIN)
        public String respondAsReady() {
            return "Demo service is ready!";
        }
     
        @GET
        @Path("sample")
        @Produces({MediaType.APPLICATION_JSON})
        public List<Country> getSamplePerson() {
     
        	CountryDaoImpl countryDao = new CountryDaoImpl();
     
        	return countryDao.findAll();
        }
    }
    Voilà mon fichier web.xml :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
      <display-name>RestWebService</display-name>
      <welcome-file-list>
        <welcome-file>index.html</welcome-file>
        <welcome-file>index.htm</welcome-file>
        <welcome-file>index.jsp</welcome-file>
        <welcome-file>default.html</welcome-file>
        <welcome-file>default.htm</welcome-file>
        <welcome-file>default.jsp</welcome-file>
      </welcome-file-list>
     
      <servlet>
        <servlet-name>Jersey REST Service</servlet-name>
        <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
     
        <init-param>
            <param-name>com.sun.jersey.config.property.packages</param-name>
            <param-value>com.businesschat.resource</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
      </servlet>
      <servlet-mapping>
        <servlet-name>Jersey REST Service</servlet-name>
        <url-pattern>/rest/*</url-pattern>
      </servlet-mapping>
      
    </web-app>
    Quand j'accède à l'url : http://localhost:8082/WS_BusinessCha...Country/sample, les erreurs ci-dessous apparaissent :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    juil. 25, 2013 9:06:27 PM com.sun.jersey.spi.container.ContainerResponse logException
    Grave: Mapped exception to response: 500 (Internal Server Error)
    javax.ws.rs.WebApplicationException: javax.xml.bind.MarshalException
     - with linked exception:
    [com.sun.istack.internal.SAXException2: A cycle is detected in the object graph. This will cause infinitely deep XML: com.businesschat.model.Country@1ac5579 -> com.businesschat.model.City@1418853 -> com.businesschat.model.Country@1ac5579]
    	at com.sun.jersey.core.provider.jaxb.AbstractListElementProvider.writeTo(AbstractListElementProvider.java:266)
    	at com.sun.jersey.spi.container.ContainerResponse.write(ContainerResponse.java:306)
    	at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1479)
    	at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1391)
    	at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1381)
    	at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:416)
    	at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:538)
    	at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:716)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    	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:291)
    	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
    	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
    	at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
    	at java.lang.Thread.run(Unknown Source)
    Caused by: javax.xml.bind.MarshalException
     - with linked exception:
    [com.sun.istack.internal.SAXException2: A cycle is detected in the object graph. This will cause infinitely deep XML: com.businesschat.model.Country@1ac5579 -> com.businesschat.model.City@1418853 -> com.businesschat.model.Country@1ac5579]
    	at com.sun.xml.internal.bind.v2.runtime.MarshallerImpl.write(Unknown Source)
    	at com.sun.xml.internal.bind.v2.runtime.MarshallerImpl.marshal(Unknown Source)
    	at com.sun.jersey.json.impl.provider.entity.JSONListElementProvider.writeList(JSONListElementProvider.java:145)
    	at com.sun.jersey.core.provider.jaxb.AbstractListElementProvider.writeTo(AbstractListElementProvider.java:264)
    	... 20 more
    Caused by: com.sun.istack.internal.SAXException2: A cycle is detected in the object graph. This will cause infinitely deep XML: com.businesschat.model.Country@1ac5579 -> com.businesschat.model.City@1418853 -> com.businesschat.model.Country@1ac5579
    	at com.sun.xml.internal.bind.v2.runtime.XMLSerializer.reportError(Unknown Source)
    	at com.sun.xml.internal.bind.v2.runtime.XMLSerializer.pushObject(Unknown Source)
    	at com.sun.xml.internal.bind.v2.runtime.XMLSerializer.childAsXsiType(Unknown Source)
    	at com.sun.xml.internal.bind.v2.runtime.property.SingleElementNodeProperty.serializeBody(Unknown Source)
    	at com.sun.xml.internal.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(Unknown Source)
    	at com.sun.xml.internal.bind.v2.runtime.XMLSerializer.childAsXsiType(Unknown Source)
    	at com.sun.xml.internal.bind.v2.runtime.property.ArrayElementNodeProperty.serializeItem(Unknown Source)
    	at com.sun.xml.internal.bind.v2.runtime.property.ArrayElementProperty.serializeListBody(Unknown Source)
    	at com.sun.xml.internal.bind.v2.runtime.property.ArrayERProperty.serializeBody(Unknown Source)
    	at com.sun.xml.internal.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(Unknown Source)
    	at com.sun.xml.internal.bind.v2.runtime.XMLSerializer.childAsSoleContent(Unknown Source)
    	at com.sun.xml.internal.bind.v2.runtime.ClassBeanInfoImpl.serializeRoot(Unknown Source)
    	at com.sun.xml.internal.bind.v2.runtime.XMLSerializer.childAsRoot(Unknown Source)
    	... 24 more
    Merci d'avance pour vos renseignements.

  2. #2
    Membre émérite
    Avatar de Cafeinoman
    Homme Profil pro
    Couteau suisse d'une PME
    Inscrit en
    Octobre 2012
    Messages
    628
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Couteau suisse d'une PME

    Informations forums :
    Inscription : Octobre 2012
    Messages : 628
    Par défaut
    On voit que c'est les vacances, personne ne répond...

    Citation Envoyé par af.zakaria Voir le message
    com.sun.istack.internal.SAXException2: A cycle is detected in the object graph
    Je suis loin d'être pro, mais l'erreur vient de SAX, donc c'est au niveau de JAXB que ça coince. Et ça parle d'un cycle, donc ça vient vraiment de ton modèle, pas de RS. Est-ce que tu peux poster ta classe country (et ton DAO tant qu'on y est...).

    Et bien sûr, si tu as trouvé en ce moment ,je veux bien la solution!

Discussions similaires

  1. Problème dans l'affichage des données en JTable
    Par sarra02 dans le forum Composants
    Réponses: 4
    Dernier message: 11/02/2015, 11h15
  2. [ZF 1.10] Problème dans l'ajout des données depuis un formulaire
    Par king_soft dans le forum Zend_Form
    Réponses: 6
    Dernier message: 24/01/2011, 09h25
  3. [displaytag] problème dans l'export des données
    Par ghotique dans le forum Struts 2
    Réponses: 6
    Dernier message: 11/03/2009, 11h25
  4. Problème dans le calcul des normales moyennes,
    Par MaxPayne dans le forum OpenGL
    Réponses: 1
    Dernier message: 12/04/2005, 17h50
  5. [ORACLE 9.2] Problème dans le Manager des tâches Win
    Par vempiria dans le forum Oracle
    Réponses: 25
    Dernier message: 12/10/2004, 09h30

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo