Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serialization and Deserialization of Type and Class #340

Closed
GoogleCodeExporter opened this issue Mar 19, 2015 · 2 comments

Comments

@GoogleCodeExporter
Copy link

commented Mar 19, 2015

I have a class like 

Class Function {

public int functionId;
public Type functionId;
public String functionName

}

public void static main ()
{
                Function fc= new Function();        
        fc.functionId(100);
        fc.functionName("Divide");

        Type tmp = new Integer(100).getClass();
        Gson gson = new GsonBuilder.create();
        System.out.println(gson.togson(fc) );
}


I am getting {} ie null for functionType Filed.
What is the issue here ? am I missing something

Original issue reported on code.google.com by DRDO.YOG...@gmail.com on 1 Jul 2011 at 5:23

@GoogleCodeExporter

This comment has been minimized.

Copy link
Author

commented Mar 19, 2015

Please post coding questions like this on our Google Group 
(https://groups.google.com/forum/#!forum/google-gson) instead of creating bug 
reports.

Not sure if your example is correct. Here are a few suggestions:
new GsonBuilder().create() is same as new Gson()

You are not using Type tmp anywhere. 
In any case, you can get it simply as: Integer.class or int.class

gson.toJson() should print all the fields of Function. Please post complete 
working code on Google group and someone will be able to help you better.

Original comment by inder123 on 1 Jul 2011 at 9:54

  • Changed state: Invalid
@GoogleCodeExporter

This comment has been minimized.

Copy link
Author

commented Mar 19, 2015

Serializing types is actually somewhat of a security problem, so we don't want 
to support it by default. A malicious .json file could cause your application 
to load classes that it wouldn't otherwise; depending on your class path 
loading certain classes could DoS your application.

But it's quite straightforward to write a type adapter to support this in your 
own app.

Original comment by limpbizkit on 1 Jul 2011 at 9:56

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.