huberflores / google-gson

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

Nullpointer exception on toJson(); #483

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
package com.thundashop.app.banner;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

public class ATest {
    class Test {
        String test = "test";
        Class something = null;
    }

    private void run() {
        Test test = new Test();
        System.out.println(test.test);

        Gson gson = new GsonBuilder().serializeNulls().create();
        String json = gson.toJson(test);
        System.out.println(json);
    }

    public static void main(String[] args) {
        ATest test = new ATest();
        test.run();
    }
}

What is the expected output? What do you see instead?
I have no idea. a string?
Fails due to Class something = null;

What version of the product are you using? On what operating system?
gson 2.2, linux ubuntu 12.04

Please provide any additional information below.

Original issue reported on code.google.com by boggib...@gmail.com on 31 Oct 2012 at 6:46

GoogleCodeExporter commented 9 years ago

Forgot the stack trace:

Exception in thread "main" java.lang.NullPointerException
    at com.google.gson.internal.bind.TypeAdapters$1.write(TypeAdapters.java:64)
    at com.google.gson.internal.bind.TypeAdapters$1.write(TypeAdapters.java:61)
    at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:68)
    at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.write(ReflectiveTypeAdapterFactory.java:89)
    at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(ReflectiveTypeAdapterFactory.java:195)
    at com.google.gson.Gson.toJson(Gson.java:586)
    at com.google.gson.Gson.toJson(Gson.java:565)
    at com.google.gson.Gson.toJson(Gson.java:520)
    at com.google.gson.Gson.toJson(Gson.java:500)
    at com.thundashop.app.banner.ATest.run(ATest.java:17)
    at com.thundashop.app.banner.ATest.main(ATest.java:24)
Java Result: 1

Original comment by boggib...@gmail.com on 31 Oct 2012 at 6:47

GoogleCodeExporter commented 9 years ago
Fixed with r1226.

Original comment by limpbizkit on 4 Feb 2013 at 3:53