ChineSouad / google-gson

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

GSON should permit the empty string as a property name in a map #256

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I have recently upgraded from GSON 1.3 to GSON 1.4 and now I'm getting an 
exception with code that worked correct before. I also tested GSON 1.5 and it 
behaves the same as 1.4, throwing the exception.
Below is the stack trace:

Caused by: java.lang.IllegalArgumentException: condition failed: false
        at com.google.gson.Preconditions.checkArgument(Preconditions.java:39)
        at com.google.gson.JsonObject.add(JsonObject.java:55)
        at com.google.gson.DefaultTypeAdapters$MapTypeAdapter.serialize(DefaultTypeAdapters.java:519)
        at com.google.gson.DefaultTypeAdapters$MapTypeAdapter.serialize(DefaultTypeAdapters.java:498)
        at com.google.gson.JsonSerializationVisitor.findAndInvokeCustomSerializer(JsonSerializationVisitor.java:186)
        at com.google.gson.JsonSerializationVisitor.visitFieldUsingCustomHandler(JsonSerializationVisitor.java:205)
        at com.google.gson.ObjectNavigator.navigateClassFields(ObjectNavigator.java:150)
        at com.google.gson.ObjectNavigator.accept(ObjectNavigator.java:123)
        at com.google.gson.JsonSerializationVisitor.getJsonElementForChild(JsonSerializationVisitor.java:148)
        at com.google.gson.JsonSerializationVisitor.addAsChildOfObject(JsonSerializationVisitor.java:126)
        at com.google.gson.JsonSerializationVisitor.visitObjectField(JsonSerializationVisitor.java:113)
        at com.google.gson.ObjectNavigator.navigateClassFields(ObjectNavigator.java:156)
        at com.google.gson.ObjectNavigator.accept(ObjectNavigator.java:123)
        at com.google.gson.JsonSerializationContextDefault.serialize(JsonSerializationContextDefault.java:56)
        at com.google.gson.JsonSerializationContextDefault.serialize(JsonSerializationContextDefault.java:49)
        at com.google.gson.DefaultTypeAdapters$CollectionTypeAdapter.serialize(DefaultTypeAdapters.java:452)
        at com.google.gson.DefaultTypeAdapters$CollectionTypeAdapter.serialize(DefaultTypeAdapters.java:435)
        at com.google.gson.JsonSerializationVisitor.findAndInvokeCustomSerializer(JsonSerializationVisitor.java:186)
        at com.google.gson.JsonSerializationVisitor.visitUsingCustomHandler(JsonSerializationVisitor.java:161)
        at com.google.gson.ObjectNavigator.accept(ObjectNavigator.java:98)
        at com.google.gson.JsonSerializationContextDefault.serialize(JsonSerializationContextDefault.java:56)
        at com.google.gson.Gson.toJsonTree(Gson.java:230)
        at com.google.gson.Gson.toJson(Gson.java:315)
        at com.google.gson.Gson.toJson(Gson.java:270)
        at com.google.gson.Gson.toJson(Gson.java:250)

Happens when I call gson.toJson() passing a list of objects. If it is not 
obvious what changed in Preconditions.checkArgument(Preconditions.java:39) 
between versions 1.3 and 1.4 I can submit the actual object that is causing 
this exception.

Original issue reported on code.google.com by kosta.kr...@gmail.com on 26 Oct 2010 at 11:27

GoogleCodeExporter commented 9 years ago
Ok, I have done some further investigation and found out the cause.

Basically, what causes the exception is a Map<String, String> that contains an 
empty string as a key. Adding a space does nothing either, I have to enter a 
non-empty value in order to avoid it.

Due to the fact that this used to work in 1.3, I believe it is a regression 
bug, unless this has been outlined elsewhere.

Original comment by kosta.kr...@gmail.com on 26 Oct 2010 at 1:08

GoogleCodeExporter commented 9 years ago

Original comment by limpbizkit on 31 Oct 2010 at 2:34

GoogleCodeExporter commented 9 years ago
Fixed in subversion.

Original comment by limpbizkit on 31 Oct 2010 at 2:38