Hi,

I have a problem about using REST with JSON and GWT. I created a small web 
service with Restlet simulating a lottery and I have a resource /tirages that 
sends me all the drawings made since the last reset.
The GET method returns a container that contains all draws.

public class ContainerTirages implements Serializable {
private static final long serialVersionUID = 1L;
public List<Tirage> tirages_list;

public List<Tirage> getTirage_list() {
return tirages_list;
}

public void setTirage_list(List<Tirage> tirages_list) {
this.tirages_list = tirages_list;
}

public ContainerTirages() {
tirages_list = new ArrayList<Tirage>();
}

public ContainerTirages(List<Tirage> tirage_list) {
this.tirages_list = tirage_list;
}
}

public class Tirage implements Serializable {
private static final long serialVersionUID = 1L;

@Id Long Id;
private int noTirage;
private int[] numeros=new int[6];
private String dateHeure;

public int getNoTirage() {
return noTirage;
}

public void setNoTirage(int no) {
noTirage=no;
}

public int[] getNumeros() {
return numeros;
}

public void setNumeros(int[] num) {
for (int i=0 ; i<6 ; i++)
numeros[i]=num[i];
}


public String getDateHeure() {
return dateHeure;
}
public void setDateHeure(String dateTime) {
dateHeure=dateTime;
}
}

If I do not declare ContainerTirages as serializable, the server works 
correctly and when I invoke this resource in any web brower, I get :

{"tirages_list":[{"numeros":[24,8,4,19,32,18],"noTirage":1,"dateHeure":"06/03/2012
 10:13:03"},{"numeros":[15,23,1,41,22,37],"noTirage":2,"dateHeure":"06/03/2012 
10:52:59" ...

But, in this case, The GWT client do not works correctly because 
ContainerTriages is not serializable.

If I declare ContainerTirages as serializable, the client works correctly but 
when I invoke this resource in any web brower, I get this strange result:

//OK[19,11,17,20,38,33,6,6,13,18,'Fo',4,3,27,20,13,41,35,39,6,6,12,17,'Fg',4,3,21,28,31,19,16,15,6,6,11,16,'FZ',4,3,27,2,28,3,47,29,6,6,10,15,'FS',4,3,26,47,17,6,46,27,6,6,9,14,'FL',4,3,25,46,9,15,18,22,6,6,8,13,'FA',4,3,5,46,2,18,...

I tried to put restlet.ext.gwt.jar after org.restlet.ext.jackson.jar in the 
classpath. To do this, I wrote these lines in my server:

Engine.getInstance().getRegisteredConverters().clear();
Engine.getInstance().getRegisteredConverters().add(new JacksonConverter());
Engine.getInstance().getRegisteredConverters().add(new GwtConverter());

In this case, data obtained by calling the browser are correct, but the client 
can't retrieve data and generates this error: "can not parse the enclosed 
entity".

Do you have an explanation ?

Best regards
Vincent ROBERT

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2934374

Reply via email to