From: Kai Moritz Date: Sat, 15 Feb 2020 13:37:10 +0000 (+0100) Subject: WIP:Ported app to Thymeleaf 3.0.x - Überflüssiger code (simple-mapper) X-Git-Url: https://juplo.de/gitweb/?p=juplo-dialect;a=commitdiff_plain;h=2ebd13014f98d349aa147185dac2dd860fccf225 WIP:Ported app to Thymeleaf 3.0.x - Überflüssiger code (simple-mapper) --- diff --git a/src/main/java/de/juplo/thymeleaf/ImportVariablesAttributeProcessor.java b/src/main/java/de/juplo/thymeleaf/ImportVariablesAttributeProcessor.java index 8835e37..5f3cb5b 100644 --- a/src/main/java/de/juplo/thymeleaf/ImportVariablesAttributeProcessor.java +++ b/src/main/java/de/juplo/thymeleaf/ImportVariablesAttributeProcessor.java @@ -6,8 +6,6 @@ import de.juplo.simplemapper.SimpleMapper; import java.io.IOException; import java.util.HashMap; import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -292,86 +290,4 @@ public class ImportVariablesAttributeProcessor extends AbstractAttributeTagProce Map variables = new HashMap<>(); return variables; } - - - static Object convert(JsonParser parser) throws IOException - { - JsonToken token = parser.getCurrentToken(); - if (token == null) - fail(parser, "unexpected EOF"); - - switch (token) - { - case VALUE_STRING: return parser.getText(); - case VALUE_NUMBER_INT: return parser.getIntValue(); - case VALUE_NUMBER_FLOAT: return parser.getDoubleValue(); - case START_OBJECT: return convertObject(parser); - case START_ARRAY: return convertArray(parser); - case VALUE_TRUE: return Boolean.TRUE; - case VALUE_FALSE: return Boolean.FALSE; - case VALUE_NULL: return null; - } - - fail(parser, "unexpected token " + token.toString()); - return null; // << Will never be reached, because fail always throws an exception - } - - static Map convertObject(JsonParser parser) throws IOException - { - JsonToken token = parser.nextToken(); - if (token == null) - fail(parser, "unexpected EOF"); - - Map map = new LinkedHashMap<>(); - - while (!JsonToken.END_OBJECT.equals(token)) - { - if (!JsonToken.FIELD_NAME.equals(token)) - fail(parser, "expected a field-name"); - - String name = parser.getText(); - parser.nextToken(); - Object value = convert(parser); - map.put(name, value); - - token = parser.nextToken(); - if (token == null) - fail(parser, "unexpected EOF"); - } - - return map; - } - - static List convertArray(JsonParser parser) throws IOException - { - JsonToken token = parser.nextToken(); - if (token == null) - fail(parser, "unexpected EOF"); - - List list = new LinkedList<>(); - - while (!JsonToken.END_ARRAY.equals(token)) - { - list.add(convert(parser)); - - token = parser.nextToken(); - if (token == null) - fail(parser, "unexpected EOF"); - } - - return list; - } - - static void fail(JsonParser parser, String message) - { - JsonLocation location = parser.getCurrentLocation(); - LOG.error( - "{} at char-offset {} (line {}, column {})", - message, - location.getCharOffset(), - location.getLineNr(), - location.getColumnNr() - ); - throw new RuntimeException("Cannot parse JSON: " + message); - } }