Skip to content

Instantly share code, notes, and snippets.

@ajduke

ajduke/Exe34.java

Created Jan 5, 2014
Embed
What would you like to do?
package in.ajduke.ap013;
import com.google.gson.FieldNamingPolicy;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
public class Example34 {
public static void main(String[] args) {
Gson gson = new Gson();
String json = gson.toJson(new JsonClass());
System.out.println("Default behaviour....");
System.out.println(json);
gson = new GsonBuilder().setFieldNamingPolicy(
FieldNamingPolicy.LOWER_CASE_WITH_DASHES).create();
json = gson.toJson(new JsonClass());
System.out.println("\nFields with lower case with dashes...");
System.out.println(json);
gson = new GsonBuilder().setFieldNamingPolicy(
FieldNamingPolicy.UPPER_CAMEL_CASE_WITH_SPACES).create();
json = gson.toJson(new JsonClass());
System.out.println("\nFields with upper case with spaces...");
System.out.println(json);
}
}
class JsonClass {
String myField = "value1";
String myAnotherField = "value2";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.