Quantcast
Channel: Best way to map json to a Java object - Stack Overflow
Viewing all articles
Browse latest Browse all 4

Answer by Marvin Pinto for Best way to map json to a Java object

$
0
0

Here's an example using Google Gson.

public class MyObject {  private String id;  private String name;  // Getters  public String getId() { return id; }  public String getName() { return name; }}

And to access it:

MyObject obj = new Gson().fromJson(jsonString, MyObject.class);System.out.println("ID: "+obj.getId());System.out.println("Name: "+obj.getName());

As far as the best way, well that's subjective. This is one way you can accomplish what you need.


Viewing all articles
Browse latest Browse all 4

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>