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

Support custom String stub for null values #416

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

Support custom String stub for null values #416

GoogleCodeExporter opened this issue Mar 19, 2015 · 5 comments

Comments

@GoogleCodeExporter
Copy link

What steps will reproduce the problem?

import java.util.HashMap;
import java.util.Map;

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

public class GsonNullExample {
    public static void main(String[] args) {
        Map<String, String> map = new HashMap<String, String>();
        map.put("key", null);
        Gson gson = new GsonBuilder().serializeNulls().create();
        System.out.println(gson.toJson(map));
    }
}


What is the expected output? What do you see instead?
The output is:
   {"key":null}

I would like the option to set a custom value for null, e.g. "" :
   {"key":""}

Perhaps serializeNulls() could be overloaded to serializeNulls(String 
nullStringValue), to allow custom String instead of the word "null".

What version of the product are you using? On what operating system?
gson 2.1 on Mac OSx using Eclipse.

Please provide any additional information below.

Original issue reported on code.google.com by a...@matan.name on 28 Feb 2012 at 5:48

@crfnunes
Copy link

This problem still happens on version 2.8.5.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants