abhisheksharma85 / gwtprojsonserializer

Automatically exported from code.google.com/p/gwtprojsonserializer
0 stars 0 forks source link

"Can't find object serializer for usertype" #3

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. with gwt2.0.3 : serializer.serialize(usertype) throwing an exception of
"Can't find object serializer for usertype" 

the class code 

public class UserType  implements
com.kfuntak.gwt.json.serialization.client.JsonSerializable {

     private long id;
     private String type;
     private int value;
     private String description;

    public UserType() {
    }

    public long getId() {
        return this.id;
    }

    public void setId(long id) {
        this.id = id;
    }
    public String getType() {
        return this.type;
    }

    public void setType(String type) {
        this.type = type;
    }
    public int getValue() {
        return this.value;
    }

    public void setValue(int value) {
        this.value = value;
    }
    public String getDescription() {
        return this.description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

}
de-serialization works ;but serialization fails

What is the expected output? What do you see instead?

What version of the product are you using? On what operating system?
Ubuntu (lucid)

Please provide any additional information below.

Original issue reported on code.google.com by sridher....@gmail.com on 24 May 2010 at 3:31

GoogleCodeExporter commented 8 years ago
I got the same problem with the same setup, GWT 2.0.3 and a simple class to 
serialize.

Original comment by durin_mu...@hotmail.com on 8 Jun 2010 at 7:29

GoogleCodeExporter commented 8 years ago
I am getting the same problem, using GWT 2.0.3, attempting to serialize a 
simple class

Original comment by dcott...@gmail.com on 16 Jun 2010 at 6:56

GoogleCodeExporter commented 8 years ago
changing getTypeName in Serializer.java to: 

    static protected String getTypeName( Object obj ){
        String typeName =  obj.getClass().getName(); 
        return typeName; 
    }

resolves the problem 

Original comment by stefan.l...@gmail.com on 18 Jun 2010 at 5:38

GoogleCodeExporter commented 8 years ago
Got the same problem, and did what was suggest above but still the same 
problem. 

The method getObjectSerializer( String name ) is returning nothing and thus the 
serializer is null. The serializableTypes() method which is called inside 
getObjectSerializer( String name ) is simply returning {} 

I really need to fix this problem. 

Original comment by ciaran.m...@gmail.com on 18 Aug 2010 at 9:23

GoogleCodeExporter commented 8 years ago
Hi,

I have made gwtprojsonserializer just with compilation of some other GWT json 
serializers. I have also made it compatible with GWT 2.0+. If anyone has some 
fixes and want to improve code please contact me to add you to project 
contributors.

These informations are not enough to me to fix problem. Ciaran, could You send 
me your domain model or send me just all your classes which implements my 
com.kfuntak.gwt.json.serialization.client.JsonSerializable interface.

I use gwtprojsonserializer in all my GWT projects which contact services for 
json response. It has some limitations and domain model must consider them.

Original comment by kfun...@gmail.com on 18 Aug 2010 at 10:18

GoogleCodeExporter commented 8 years ago
I had the same problem (with GWT 2.0.3 too). I debug through the code and I 
agree with Stephan, there is a problem with getTypeName. Map SERIALIZABLE_TYPES 
contains the full class name of the classes implementing JsonSerializable.

As you can see in getTypeName:
static protected String getTypeName( Object obj ){
    String typeName = GWT.getTypeName( obj );
    typeName = typeName.substring(typeName.lastIndexOf('.')+1);
    return typeName.toLowerCase();
}
the full class name is stripped down to the lowercase class name. 

I am not sure what is the reason for that.

kfuntak, I think you should be able to reproduce this by modify the unit in 
SerializerTest.java as following:

[...]
University university = (University)serializer.deSerialize( jsonText, 
"com.kfuntak.gwt.json.serialization.client.domain.University");
if (university != null) {
    System.out.println(university.toString());
}
JSONValue jsonValue = serializer.serializeToJson( university );
[...]

If you deserialize to a class mypackage.MyClass, the error message will be: 
Can't find object serializer for myclass

I modified and compiled the code. I attach the JAR to this comment.

kfuntak, if you give the permission, I can update the code on the repository.

Matthias

Original comment by matthias.buchner on 25 Aug 2010 at 8:24

Attachments:

GoogleCodeExporter commented 8 years ago
I fixed few more bugs. As I haven't the permissions to submit my changes, I 
post a new version of the JAR here.

Original comment by matthias.buchner on 2 Sep 2010 at 4:39

Attachments:

GoogleCodeExporter commented 8 years ago
Here is a simple patch that solves the serialization problem (explained above) 
(+ some list/collection (de)serialization issues, ie. don't throw exception 
when field is missing in json,...). 

...and a minor correction to SerializerTest.java (no need for toString()):
[...]
University university = (University)serializer.deSerialize(jsonText, 
"com.kfuntak.gwt.json.serialization.client.domain.University");
if (university != null) {
  System.out.println(serializer.serialize(university));
}
[...]

Sasa

Original comment by sasa...@gmail.com on 1 Oct 2010 at 12:58

Attachments:

GoogleCodeExporter commented 8 years ago

Original comment by remi.barraquand on 17 Oct 2010 at 5:25