Code example for JsonPrimitive

0
      Manager result = new Manager();
      result.userid = json.getAsString();
      return result;
    } 
    public JsonElement serialize(Manager src, Type typeOfSrc, JsonSerializationContext context) {
      return new JsonPrimitive(src.userid);
    } 
  } 
 
  static class EmployeeAdapter implements JsonSerializer<Employee>, JsonDeserializer<Employee> {
    public JsonElement serialize(Employee employee, Type typeOfSrc,
        JsonSerializationContext context) {
      JsonObject result = new JsonObject();
      result.add("userid", context.serialize(employee.userid, String.class));
      result.add("startDate", context.serialize(employee.startDate, long.class));
      if (employee instanceof Manager) {
        result.add("minions", context.serialize(((Manager) employee).minions, Employee[].class));
        if (employee instanceof CEO) {
          result.add("assistant", context.serialize(((CEO) employee).assistant, Employee.class));
        } 
Contextual code suggestions in your IDE  Get Codota for Java