From ad145f3c3d843239d273cee29683e32ba04eb0d2 Mon Sep 17 00:00:00 2001 From: Daniel Kirschten Date: Mon, 16 Sep 2019 17:23:29 +0200 Subject: [PATCH] JsonHandler preserves line numbers --- .../src/net/mograsim/logic/model/util/JsonHandler.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/plugins/net.mograsim.logic.model/src/net/mograsim/logic/model/util/JsonHandler.java b/plugins/net.mograsim.logic.model/src/net/mograsim/logic/model/util/JsonHandler.java index 20491ce5..d2d6de31 100644 --- a/plugins/net.mograsim.logic.model/src/net/mograsim/logic/model/util/JsonHandler.java +++ b/plugins/net.mograsim.logic.model/src/net/mograsim/logic/model/util/JsonHandler.java @@ -39,8 +39,13 @@ public class JsonHandler public static T fromJson(String src, Class type) { - // throw away legacy version line - String rawJson = src.lines().dropWhile(s -> s.length() == 0 || s.charAt(0) != '{').collect(Collectors.joining()); + // throw away legacy version line, but keep line numbers + int linesBeforeJsonStart = (int) src.lines().takeWhile(s -> s.length() == 0 || s.charAt(0) != '{').count(); + String rawJson; + if (linesBeforeJsonStart == 0) + rawJson = src; + else + rawJson = "\n".repeat(linesBeforeJsonStart) + src.lines().skip(linesBeforeJsonStart).collect(Collectors.joining("\n")); return parser.fromJson(rawJson, type); } -- 2.17.1