Skip to content
Snippets Groups Projects
Commit 83d452ee authored by Ramin Yaghoubzadeh Torky's avatar Ramin Yaghoubzadeh Torky
Browse files

Java: pseudoConvert now uses StringEscapeUtils for correct unescaping

(This was sufficient for basic interoperation, e.g. DM<->realizer)
parent da4a3b00
No related branches found
No related tags found
No related merge requests found
......@@ -9,5 +9,6 @@
<dependency org="google" name="protobuf-java" rev="latest.release" />
<dependency org="rsb" name="rsb" rev="latest.release" />
<dependency org="lombok" name="lombok" rev="latest.release" />
<dependency org="apache" name="commons-lang" rev="latest.release" />
</dependencies>
</ivy-module>
......@@ -34,6 +34,8 @@ package ipaaca;
import ipaaca.protobuf.Ipaaca.PayloadItem;
import org.apache.commons.lang.StringEscapeUtils;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
......@@ -93,18 +95,19 @@ public class Payload implements Map<String, String>
map.put(item.getKey(), pseudoConvertFromJSON(item.getValue(), item.getType()));
}
}
public String pseudoConvertFromJSON(String value, String type) {
if (type.equals("JSON")) {
if (value.startsWith("\"")) {
return value.replaceAll("\\\"", "");
} else if (value.startsWith("{") || value.startsWith("[") || value.matches("true") || value.matches("false") || value.matches("-?[0-9]*[.,]?[0-9][0-9]*.*")) {
return value;
} else if (value.equals("null")) {
return "";
}
}
return value;
if (type.equals("JSON")) {
if (value.startsWith("\"")) {
//return value.replaceAll("\\\"", "");
return StringEscapeUtils.unescapeJava(value.substring(1, value.length() - 1));
} else if (value.startsWith("{") || value.startsWith("[") || value.matches("true") || value.matches("false") || value.matches("-?[0-9]*[.,]?[0-9][0-9]*.*")) {
return value;
} else if (value.equals("null")) {
return "";
}
}
return value;
}
void enforcedSetItem(String key, String value)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment