fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. public class DataModelDeserializer<T> implements JsonDeserializer<T> {
  4.  
  5. @Override
  6. public T deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
  7. JsonElement items=null;
  8.  
  9. try{
  10. items = jsonElement.getAsJsonObject();
  11. }catch (Exception e){
  12. System.out.println("[ERROR] An error has accused while parsing the response.");
  13. System.out.println("[ERROR] DataModel: " + jsonElement);
  14. throw new JsonIOException("Check your profile.");
  15. }
  16.  
  17. return new Gson().fromJson(items, type);
  18. }
  19. }
  20.  
  21. public class DataModel {
  22. private Response response;
  23.  
  24.  
  25. public Response getResponse() {
  26. return response;
  27. }
  28.  
  29. public void setResponse(Response response) {
  30. this.response = response;
  31. }
  32.  
  33.  
  34. }
  35.  
  36. public class Response<T> {
  37. private int count;
  38. private List<T> items=new ArrayList<T>();
  39. public int getCount() {
  40. return count;
  41. }
  42.  
  43. public void setCount(int count) {
  44. this.count = count;
  45. }
  46.  
  47. public List<T> getItems() {
  48. return items;
  49. }
  50.  
  51. public void setItems(List<T> items) {
  52. this.items = items;
  53. }
  54. }
  55.  
  56. public class Items {
  57. private int id;
  58. public int getId() {
  59. return id;
  60. }
  61.  
  62. public void setId(int id) {
  63. this.id = id;
  64. }
  65. }
  66.  
  67.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:3: error: class DataModelDeserializer is public, should be declared in a file named DataModelDeserializer.java
public class DataModelDeserializer<T> implements JsonDeserializer<T> {
       ^
Main.java:21: error: class DataModel is public, should be declared in a file named DataModel.java
public class DataModel {
       ^
Main.java:36: error: class Response is public, should be declared in a file named Response.java
public class Response<T> {
       ^
Main.java:56: error: class Items is public, should be declared in a file named Items.java
public class Items {
       ^
Main.java:3: error: cannot find symbol
public class DataModelDeserializer<T> implements JsonDeserializer<T> {
                                                 ^
  symbol: class JsonDeserializer
Main.java:6: error: cannot find symbol
    public T deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
                         ^
  symbol:   class JsonElement
  location: class DataModelDeserializer<T>
  where T is a type-variable:
    T extends Object declared in class DataModelDeserializer
Main.java:6: error: cannot find symbol
    public T deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
                                                  ^
  symbol:   class Type
  location: class DataModelDeserializer<T>
  where T is a type-variable:
    T extends Object declared in class DataModelDeserializer
Main.java:6: error: cannot find symbol
    public T deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
                                                             ^
  symbol:   class JsonDeserializationContext
  location: class DataModelDeserializer<T>
  where T is a type-variable:
    T extends Object declared in class DataModelDeserializer
Main.java:6: error: cannot find symbol
    public T deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
                                                                                                                           ^
  symbol:   class JsonParseException
  location: class DataModelDeserializer<T>
  where T is a type-variable:
    T extends Object declared in class DataModelDeserializer
Main.java:38: error: cannot find symbol
    private List<T> items=new ArrayList<T>();
            ^
  symbol:   class List
  location: class Response<T>
  where T is a type-variable:
    T extends Object declared in class Response
Main.java:47: error: cannot find symbol
    public List<T> getItems() {
           ^
  symbol:   class List
  location: class Response<T>
  where T is a type-variable:
    T extends Object declared in class Response
Main.java:51: error: cannot find symbol
    public void setItems(List<T> items) {
                         ^
  symbol:   class List
  location: class Response<T>
  where T is a type-variable:
    T extends Object declared in class Response
Main.java:5: error: method does not override or implement a method from a supertype
    @Override
    ^
Main.java:7: error: cannot find symbol
        JsonElement items=null;
        ^
  symbol:   class JsonElement
  location: class DataModelDeserializer<T>
  where T is a type-variable:
    T extends Object declared in class DataModelDeserializer
Main.java:14: error: cannot find symbol
            throw new JsonIOException("Check your profile.");
                      ^
  symbol:   class JsonIOException
  location: class DataModelDeserializer<T>
  where T is a type-variable:
    T extends Object declared in class DataModelDeserializer
Main.java:17: error: cannot find symbol
        return new Gson().fromJson(items, type);
                   ^
  symbol:   class Gson
  location: class DataModelDeserializer<T>
  where T is a type-variable:
    T extends Object declared in class DataModelDeserializer
Main.java:38: error: cannot find symbol
    private List<T> items=new ArrayList<T>();
                              ^
  symbol:   class ArrayList
  location: class Response<T>
  where T is a type-variable:
    T extends Object declared in class Response
17 errors
stdout
Standard output is empty