shupakabras / gwtprojsonserializer

0 stars 0 forks source link

NullPointerException on serialize function #27

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create an object "Person" that implements JsonSerializable and contains 
another JsonSerializable object "Child", but this one is null.
2. Call GWT.<Serializer>create(Serializer.class).serialize(person);
3.

What is the expected output? What do you see instead?
A NullPointerException is thrown when 'getTypeName' method for the "Child" 
object is accessed.

What version of the product are you using? On what operating system?
Last Version of gwtprojsonserializer.

Please provide any additional information below.

Original issue reported on code.google.com by fra...@gmail.com on 11 Sep 2011 at 2:02

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
I suggest a patch to solve this problem :

In Serializer class, in the serializeToJson(Object pojo):JSONValue method, if 
you add a condition to test the null value, you resolve the problem.

public JSONValue serializeToJson(Object pojo) {
    // 2011/11/23 : Fabien PERIE
    // Patch to resolve a NullPointerException is thrown when 'getTypeName' method for the "Child"
    // object is accessed.
    if (pojo == null)
    {
    return JSONNull.getInstance();
    }

    String name = getTypeName(pojo);
    ObjectSerializer serializer = getObjectSerializer(name);
    if (serializer == null) {
            throw new SerializationException("Can't find object serializer for " + name);
    }
    return serializer.serializeToJson(pojo);
}

Original comment by fabien.p...@gmail.com on 24 Nov 2011 at 1:04

Attachments: