Commit 41376492 authored by Adam Knapp's avatar Adam Knapp
Browse files

Fixing handling of JSON defaults (issue #416)


Signed-off-by: Adam Knapp's avatarAdam Knapp <adam.knapp@ericsson.com>
parent c0976df4
......@@ -85,6 +85,9 @@ public class CharstringExtractor {
* @return extracted string value
*/
private String extractString(final String aTtcnCharstring) {
if (aTtcnCharstring.equals("\"\"")) {
return aTtcnCharstring;
}
final int slength = aTtcnCharstring.length();
int pointer = 0;
final StringBuilder sb = new StringBuilder();
......
......@@ -2082,6 +2082,12 @@ public final class RecordSetCodeGenerator {
source.append("\t\t/** {@inheritDoc} *"+"/\n");
source.append("\t\tpublic int JSON_decode(final TTCN_Typedescriptor p_td, final JSON_Tokenizer p_tok, final boolean p_silent, final boolean p_parent_is_map, final int p_chosen_field) {\n");
// handling default values
source.append("\t\t\tif (p_td.json.getActualDefaultValue() != null && 0 == p_tok.get_buffer_length()) {\n");
source.append("\t\t\t\toperator_assign(p_td.json.getActualDefaultValue());\n");
source.append("\t\t\t\treturn 0;\n");
source.append("\t\t\t}\n\n");
if (fieldInfos.size() == 1) {
if (!jsonAsValue) {
source.append("\t\t\tif (p_td.json.isAs_value()) {\n");
......
......@@ -1745,6 +1745,11 @@ public final class UnionGenerator {
}
source.append("\t\t\t\t}\n");
source.append("\t\t\t}\n");
// handling default values
source.append("\t\t\tif (p_td.json.getActualDefaultValue() != null && 0 == p_tok.get_buffer_length()) {\n");
source.append("\t\t\t\toperator_assign(p_td.json.getActualDefaultValue());\n");
source.append("\t\t\t\treturn 0;\n");
source.append("\t\t\t}\n\n");
source.append("\t\t\tfinal AtomicReference<json_token_t> j_token = new AtomicReference<json_token_t>(json_token_t.JSON_TOKEN_NONE);\n");
if (!jsonAsValue) {
source.append("\t\t\tif (p_td.json.isAs_value()) {\n");
......
......@@ -1196,7 +1196,8 @@ public abstract class Type extends Governor implements IType, IIncrementallyUpda
@Override
/** {@inheritDoc} */
public final void checkJsonDefault(final CompilationTimeStamp timestamp) {
final CharstringExtractor extractor = new CharstringExtractor(jsonAttribute.parsed_default_value, true);
final String preparedString = jsonAttribute.parsed_default_value.replace("\\)", ")").replaceAll("^\\\\\"|\\\\\"$", "\"\"");
final CharstringExtractor extractor = new CharstringExtractor(preparedString, true);
final String defaultValue = extractor.getExtractedString();
final JSONDefaultAnalyzer refAnalyzer = new JSONDefaultAnalyzer();
final IValue parsedValue = refAnalyzer.parseJSONDefaultValue(defaultValue, jsonAttribute.defaultLocation);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment