json-object-mapper
json-object-mapper copied to clipboard
Repeating deserialisation twice per object
Hi Team,
Please look at the below code segment from index.ts file. It's doing deserialisation twice per object because we are assigning the first element for deserialisation first and then the popped element again.
`const runDeserialization = (conversionFunctionStructures: ConversionFunctionStructure[]): void => {
const converstionFunctionsArray: Array<ConversionFunctionStructure> = [];
conversionFunctionStructures.forEach((struct: ConversionFunctionStructure) => {
converstionFunctionsArray.push(struct);
});
**let conversionFunctionStructure: ConversionFunctionStructure = converstionFunctionsArray[0];** //This line needs to be replaced with **let conversionFunctionStructure: ConversionFunctionStructure = (converstionFunctionsArray.length > 0)? converstionFunctionsArray.pop() : undefined;**
// tslint:disable-next-line:triple-equals
while (conversionFunctionStructure != undefined) {
const stackEntries: Array<ConversionFunctionStructure> = conversionFunctions[conversionFunctionStructure.functionName](
conversionFunctionStructure.instance, conversionFunctionStructure.instanceKey,
conversionFunctionStructure.type, conversionFunctionStructure.json,
conversionFunctionStructure.jsonKey);
stackEntries.forEach((structure: ConversionFunctionStructure) => {
converstionFunctionsArray.push(structure);
});
conversionFunctionStructure = converstionFunctionsArray.pop();
}
};`
This is the sample JSON which I'm trying to deserialise. When we try to deserialise complex nested objects, it's recursively calling again and again. But if we add the above condition which I mentioned, it will solve the problem.
{ "id" : 55, "references" : [ ], "groupingTarget" : false, "metaTarget" : true, "relativeDataTargets" : [ { "id" : 56, "references" : [ ], "groupingTarget" : false, "metaTarget" : false, "name" : "meta.tracked_statement_website_key", "operator" : { "regEx" : "(([0-9]{1,2})[-/\\.]([0-9]{1,2})[-/\\.]([0-9]{2,4}+))", "groupCount" : -1 }, "xPath" : "./parent::td/parent::tr/child::td[count(//th[contains(text(),'Invoice Date')]/preceding-sibling::th)+1]/text()", "variableSubstitution" : false, "reinitializeVariable" : false, "index" : 0 } ], "xPath" : ".//text()", "alternateXPaths" : null, "variableSubstitution" : false, "reinitializeVariable" : false, "index" : 0 };
@shakilsiraj I'm not sure who should I reach out. Will this be taken care? Or should I raise any PR by forking this repo? Can you guide me the next steps?