File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed
Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change 1+ package com .zetcode ;
2+
3+ import com .google .gson .FieldNamingPolicy ;
4+ import com .google .gson .Gson ;
5+ import com .google .gson .GsonBuilder ;
6+ import java .io .IOException ;
7+ import java .io .PrintStream ;
8+
9+ class User {
10+
11+ private final String firstName ;
12+ private final String lastName ;
13+
14+ public User (String firstName , String lastName ) {
15+ this .firstName = firstName ;
16+ this .lastName = lastName ;
17+ }
18+ }
19+
20+ public class GsonBuilderEx {
21+
22+ public static void main (String [] args ) throws IOException {
23+
24+ try (PrintStream prs = new PrintStream (System .out , true ,
25+ "UTF8" )) {
26+
27+ Gson gson = new GsonBuilder ()
28+ .setFieldNamingPolicy (FieldNamingPolicy .UPPER_CAMEL_CASE )
29+ .create ();
30+
31+ User user = new User ("Peter" , "Flemming" );
32+ gson .toJson (user , prs );
33+ }
34+ }
35+ }
You can’t perform that action at this time.
0 commit comments