+ * Parse each property and call the assigned property deserializer.
+ *
+ * @param nodeData NodeData to call the assigned property deserialized on.
+ * @param input String input to deserialize from.
+ * @throws IllegalArgumentException If the input format is malformed in any way.
+ */
+ public void deserialize(@NotNull T nodeData, @NotNull String input) throws IllegalArgumentException {
log.fine("Deserializing " + input);
- if (propertyEquals == null) {
- this.propertyEquals = generatePropertyEqualsPattern();
+ if (propertyEqualsPattern == null) {
+ this.propertyEqualsPattern = generatePropertyEqualsPattern();
}
// Split out the [] section with actual data
- Matcher matcher = dataPattern.matcher(input);
+ Matcher matcher = DATA_PATTERN.matcher(input);
if (!matcher.find()) {
- throw new IllegalArgumentException("Invalid node data format");
+ throw new IllegalArgumentException("Malformed node data syntax. Most likely missing ']'.");
}
String dataString = matcher.group(1);
@@ -51,18 +91,33 @@ public void deserialize(T nodeData, String input) throws IllegalArgumentExceptio
String[] dataParts = dataString.split(",");
for (String dataPart : dataParts) {
- String[] entryParts = propertyEquals.split(dataPart);
- String key = entryParts[0];
- String value = entryParts[1];
+ if (dataPart.trim().isEmpty()) {
+ log.fine("Empty data part in '" + dataString + "'");
+ continue;
+ }
+
+ Matcher keyMatcher = KEY_PATTERN.matcher(dataPart);
+
+ if (!keyMatcher.find()) {
+ throw new IllegalArgumentException(String.format("Malformed node data property part '%s'. Skipping.", dataPart));
+ }
+
+ String key = keyMatcher.group(1).substring(0, keyMatcher.end() - 1);
+ String value = dataPart.substring(keyMatcher.end());
+
+ log.fine("Key: " + key + ", value: " + value);
PropertyDeserializer