@Test public void parseFromJsonReturnsValidObjectWhenDeserializing() { SubmissionResult initial = new SubmissionResult(); initial.setError("Error"); initial.setStatus(Status.OK); List<String> list = new ArrayList<String>(); list.add("1"); list.add("2"); initial.setMissingReviewPoints(list); Gson gson = new Gson(); SubmissionResult result = parser.parseFromJson(gson.toJson(initial)); assertEquals(initial.getError(), result.getError()); assertEquals(initial.getStatus(), result.getStatus()); assertEquals(initial.getMissingReviewPoints(), result.getMissingReviewPoints()); }
public SubmissionResult parseFromJson(String json) { if (json.trim().isEmpty()) { throw new IllegalArgumentException("Empty input"); } try { Gson gson = new GsonBuilder().registerTypeAdapter(SubmissionResult.Status.class, new StatusDeserializer()) .registerTypeAdapter(StackTraceElement.class, new StackTraceSerializer()).create(); return gson.fromJson(json, SubmissionResult.class); } catch (RuntimeException e) { throw new RuntimeException("Failed to parse submission result: " + e.getMessage(), e); } }
SubmissionResultParser { public SubmissionResult parseFromJson(String json) { if (json.trim().isEmpty()) { throw new IllegalArgumentException("Empty input"); } try { Gson gson = new GsonBuilder().registerTypeAdapter(SubmissionResult.Status.class, new StatusDeserializer()) .registerTypeAdapter(StackTraceElement.class, new StackTraceSerializer()).create(); return gson.fromJson(json, SubmissionResult.class); } catch (RuntimeException e) { throw new RuntimeException("Failed to parse submission result: " + e.getMessage(), e); } } }
SubmissionResultParser { public SubmissionResult parseFromJson(String json) { if (json.trim().isEmpty()) { throw new IllegalArgumentException("Empty input"); } try { Gson gson = new GsonBuilder().registerTypeAdapter(SubmissionResult.Status.class, new StatusDeserializer()) .registerTypeAdapter(StackTraceElement.class, new StackTraceSerializer()).create(); return gson.fromJson(json, SubmissionResult.class); } catch (RuntimeException e) { throw new RuntimeException("Failed to parse submission result: " + e.getMessage(), e); } }  }
SubmissionResultParser { public SubmissionResult parseFromJson(String json) { if (json.trim().isEmpty()) { throw new IllegalArgumentException("Empty input"); } try { Gson gson = new GsonBuilder().registerTypeAdapter(SubmissionResult.Status.class, new StatusDeserializer()) .registerTypeAdapter(StackTraceElement.class, new StackTraceSerializer()).create(); return gson.fromJson(json, SubmissionResult.class); } catch (RuntimeException e) { throw new RuntimeException("Failed to parse submission result: " + e.getMessage(), e); } }  SubmissionResult parseFromJson(String json); }
SubmissionResultParser { public SubmissionResult parseFromJson(String json) { if (json.trim().isEmpty()) { throw new IllegalArgumentException("Empty input"); } try { Gson gson = new GsonBuilder().registerTypeAdapter(SubmissionResult.Status.class, new StatusDeserializer()) .registerTypeAdapter(StackTraceElement.class, new StackTraceSerializer()).create(); return gson.fromJson(json, SubmissionResult.class); } catch (RuntimeException e) { throw new RuntimeException("Failed to parse submission result: " + e.getMessage(), e); } }  SubmissionResult parseFromJson(String json);  }