This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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