Migrate from GitHub to SourceForge with this tool. Check out all of SourceForge's recent improvements.
Close

#12 JSONSerializer produces duplicate fields

1.9.2
closed-fixed
5
2010-10-16
2010-03-11
victorious
No

Point2D p = new Point2D.Float(1,2);
System.out.println(new JSONSerializer().serialize(p));

would print {"class":"java.awt.geom.Point2D$Float","x":1.0,"y":2.0,"x":1.0,"y":2.0} and JSONDeserializer would refuse to deserialize it with Exception in thread "main" flexjson.JSONException: Duplicate key "x"

I had to use flexjson source and add
Set<String> onlyOnce = new HashSet<String>(); (JSONSerializer.java line 587)
if (accessor != null && isIncluded( prop ) && !onlyOnce.contains(name)) { (JSONSerializer.java line 596)
onlyOnce.add(name); (JSONSerializer.java line 600)
if( !visits.contains( field.get(object) ) && !onlyOnce.contains(field.getName()) ) { (JSONSerializer.java line 611)
onlyOnce.add(field.getName()); (JSONSerializer.java line 613)

Hope to see this fix in next release :)

Discussion

  • Charlie Hubbard

    Charlie Hubbard - 2010-10-16
    • status: open --> closed-fixed
     
  • Charlie Hubbard

    Charlie Hubbard - 2010-10-16

    I was able to write a unit test that worked serializing the Point2D.Float so that it didn't produce duplicate x's in the json output. This is fixed in 2.1.

     

Log in to post a comment.