Skip to content

Instantly share code, notes, and snippets.

@futurehope
Created January 23, 2012 19:29
Show Gist options
  • Save futurehope/1665087 to your computer and use it in GitHub Desktop.
Save futurehope/1665087 to your computer and use it in GitHub Desktop.
This class complies and tests fine in Winter '12 but test testWithGetter fails in Spring '12
public with sharing class JSONTest {
public class noGetter {
string a = 'a';
}
public class withGetter {
string a { get{ return 'a'; }}
}
public static testMethod void testNoGetter() {
// new instance of class
JSONTest.noGetter ext = new JSONTest.noGetter();
// serialise the class instance into JSON
string encodedJSON = JSON.serialize(ext);
// check it is as expected
system.assertEquals('{"a":"a"}', encodedJSON);
// successful parse
ext = (JSONTest.noGetter) JSON.deserialize(encodedJSON, JSONTest.noGetter.class);
system.assertEquals('a', ext.a);
}
public static testMethod void testWithGetter() {
// new instance of class
JSONTest.withGetter ext = new JSONTest.withGetter();
// serialise the class instance into JSON
string encodedJSON = JSON.serialize(ext);
// check it is as expected
system.assertEquals('{"a":"a"}', encodedJSON);
// following line excutes without issue in winter '12, errors in spring '12 with:
// System.JSONException: Duplicate field: JSONTest.withGetter.a
// (System Code)
ext = (JSONTest.withGetter) JSON.deserialize(encodedJSON, JSONTest.withGetter.class);
system.assertEquals('a', ext.a);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment