Customer customer = new Customer(); Product product = new Product(); // Set your values ... Gson gson = new Gson(); String json = gson.toJson(); Curtomer deserialized = gson.fromJson(json, Customer.class);
References :
http://stackoverflow.com/questions/10930624/creating-json-objects-directly-from-model-classes-in-java