ChineSouad / google-gson

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

Failure to serialize enums with method definitions. #244

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I've attached a JUnit test file that shows the issue. I've confirmed that the 
following patch fixes this.

Existing method in Gson.java:

  public String toJson(Object src) {
    if (src == null) {
      return serializeNulls ? NULL_STRING : "";
    }
    return toJson(src, src.getClass());
  }

Patched version of above method:

  public String toJson(Object src) {
    if (src == null) {
      return serializeNulls ? NULL_STRING : "";
    }

    Type typeOfSrc;
    if (src instanceof Enum) {
      typeOfSrc = ((Enum) src).getDeclaringClass();
    } else {
      typeOfSrc = src.getClass();
    }

    return toJson(src, typeOfSrc);
  }

Original issue reported on code.google.com by MarceliN...@gmail.com on 29 Sep 2010 at 10:20

Attachments:

GoogleCodeExporter commented 9 years ago
Already fixed in SVN.

Original comment by limpbizkit on 3 Oct 2010 at 6:41