RedEagle
RedEagle

Reputation: 4560

Converting null object Gson to Json

I've been using Google's Gson API for quite some time and love its simplicity.

Nonetheless, I've found (probably) a bug on the toJson method.

When I try to convert a null object to JSON, instead of an exception, or alternatively a null String return, I get a String with the value null.

Do you consider this a bug?

Upvotes: 0

Views: 1223

Answers (2)

atish shimpi
atish shimpi

Reputation: 5023

null is not producing NullPointerException while converting because it is literal and it is valid Gson Value.

Upvotes: 0

Sotirios Delimanolis
Sotirios Delimanolis

Reputation: 280000

No, null is a valid JSON value.

Upvotes: 2

Related Questions