yasson icon indicating copy to clipboard operation
yasson copied to clipboard

Json silently returns an empty list instead of failing

Open oliviercailloux opened this issue 4 years ago • 4 comments

Describe the bug When providing a json object instead of a json array and asking Jsonb to produce a list, the library returns an empty list; whereas it should throw an exception to indicate to the caller that something is wrong.

To Reproduce

String json = "{\"name\": \"John Doe\"}";
try (Jsonb jsonb = JsonbBuilder.create()) {
	List<Person> list = jsonb.fromJson(json, new ArrayList<Person>() {
		private static final long serialVersionUID = -7485196487128234751L;
	}.getClass().getGenericSuperclass());
	/** The deserialization process returns an empty list instead of failing fast: */
	assertEquals(List.of(), list);
}

See Person and PersonTests for full details.

Expected behavior I expect that the call jsonb.fromJson in the above example throws an exception indicating that the input string is not in a format that allows to extract a list of persons (as a json array is expected and not a json object).

System information:

  • Yasson Version: 1.0.7

Additional context This bug was found by students in my course, whose GitHub usernames are Sarah-Elhelw and Semida-Buzdugan. Credits go to them.

oliviercailloux avatar Jun 24 '20 17:06 oliviercailloux