Skip to content

Instantly share code, notes, and snippets.

@ajduke
Last active January 2, 2016 07:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ajduke/8267956 to your computer and use it in GitHub Desktop.
Save ajduke/8267956 to your computer and use it in GitHub Desktop.
public class Example33 {
public static void main(String[] args) {
Gson gson = new GsonBuilder().setVersion(2.0).create();
String json = gson.toJson(new ExampleClass());
System.out.println("Output for version 2.0...");
System.out.println(json);
gson= new GsonBuilder().setVersion(1.0).create();
json = gson.toJson(new ExampleClass());
System.out.println("\nOutput for version 1.0...");
System.out.println(json);
gson= new Gson();
json = gson.toJson(new ExampleClass());
System.out.println("\nOutput for No version set...");
System.out.println(json);
}
}
class ExampleClass{
String field= "field";
// this is in version 1.0
@Since(1.0) String newField1 = "field 1";
// following will be included in the version 1.1
@Since(2.0) String newField2 = "field 2";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment