I get this problem, I don’t want to solve this problem, but find a way to tell GSON to “skip errors and continue” parsing:
Can't parses json : java.lang.IllegalStateException: Expected a string but was BEGIN_OBJECT at line 1 column 16412
Used code:
JsonReader reader = new JsonReader(new StringReader(data)); reader.setLenient(true); Articles articles = gson.create().fromJson(reader, Articles.class);
Data (for simplification): Article-> Pages-> medias.fields. One field in the current error is defined as a string, but I get an object (but again, this is only one occurrence). I cannot add protection everywhere, so my question is: is there a pass and continues in GSON?
I want to avoid JsonSysntaxException using GSON when there is a problem on node, and I expect that at least you will get parsed partial data. In my case, I would have 99.999% of the data, and only my wrong field would be null ... I know this doesn't seem clean, but I would enable "strict mode" for unit test or continuous integration to detect the problem and produce I will enable soft mode so that my application can start (even when the server side made errors). I can’t say that your application cannot be started, because the article contains invalid data.
Does GSON skip and continue by mistake?
source share