How to format an Object into JSON in Java

[CG]BOUGA
1,142 views

Open Source Your Knowledge, Become a Contributor

Technology knowledge has to be shared and made accessible for free. Join the movement.

Create Content

Using Gson

1
8
9
10
11
12
13
14
15
// {...}
User user = new User("Bob", 123);
String json = new Gson().toJson(user);
System.out.println(json);
// {...}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
1
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Open Source Your Knowledge: become a Contributor and help others learn. Create New Content