Problems with Ws

Asked

Viewed 40 times

1

inserir a descrição da imagem aquiPersonal I am when runs the page to generate the json it only tras null , already I checked it is taking the data of the database the stranger and q is giving this message :

Information: Scanning for root Resource and Provider classes in the Packages: Resource Information: Root Resource classes found:
class Resource.stockResource Information: In the classes Provider found. Information: Initiating Jersey application, version 'Jersey: 1.11 12/09/2011 10:27 AM'

    /*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Resource;

import Controller.estoqueControler;
import Model.ESTOQUE;
import java.util.ArrayList;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;

/**
 *
 * @author Felipee[![inserir a descrição da imagem aqui][1]][1]
 */
@Path("/estoque")
public class estoqueResource {

    @GET
    @Path("/Estoque")
    @Produces("application/json")
    public ArrayList<ESTOQUE> ESTOQUE() {
        return new estoqueControler().ESTOQUE();
    }
}
  • Post the code.

  • 1

    post , just can’t leave the right way there

  • someone ???

1 answer

0


Jersey does not support automatic serialization of any kind, in this case ArrayList.

A Provider is a special type of class that checks the type of return of the method and the format it is producing and, if compatible, it acts by automatically selecting the object in that format.

You can write your own Provider, but the easiest solution is to provide an object in return that is compatible with an existing Preview. Simply create a class annotated with @XmlRootElement and place an attribute with the list inside the object.

Another option is to serialize the list within the method using a JSON library directly and return one String, 'cause then Jersey won’t need a Provider. The advantage of this approach is flexibility, but it also leaves the code "dirtier".

Browser other questions tagged

You are not signed in. Login or sign up in order to post.