Skip to content

Commit 19ee7ef

Browse files
akoclaude
andcommitted
fix: mapping JsonPath must use ExposedName, not original JSON key
The JSON structure's ExposedName (custom name) must be used in mapping element JsonPaths. E.g., with CUSTOM NAME MAP ('id' AS '_id'), the mapping JsonPath must be '(Object)|_id' not '(Object)|id'. Lookup still uses the original key path to find the JSON structure element, but the mapping's JsonPath is built from ExposedName. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent db44d87 commit 19ee7ef

File tree

2 files changed

+33
-26
lines changed

2 files changed

+33
-26
lines changed

mdl/executor/cmd_export_mappings.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -301,26 +301,30 @@ func buildExportMappingElementModel(moduleName string, def *ast.ExportMappingEle
301301
var jsonPath string
302302
if isRoot {
303303
jsonPath = parentPath // "(Object)"
304-
// Root must have empty ExposedName
305304
elem.ExposedName = ""
306305
if info, ok := jsElements[jsonPath]; ok {
307306
elem.MaxOccurs = info.MaxOccurs
308307
}
308+
elem.JsonPath = jsonPath
309309
} else {
310-
candidatePath := parentPath + "|" + def.JsonName
311-
if info, ok := jsElements[candidatePath]; ok {
310+
// Look up by original JSON key, then use ExposedName for the mapping's JsonPath
311+
lookupPath := parentPath + "|" + def.JsonName
312+
if info, ok := jsElements[lookupPath]; ok {
312313
elem.ExposedName = info.ExposedName
313314
elem.MaxOccurs = info.MaxOccurs
315+
jsonPath = parentPath + "|" + info.ExposedName
314316
if info.ElementType == "Array" {
315-
jsonPath = candidatePath + "|(Object)"
316-
} else {
317-
jsonPath = candidatePath
317+
jsonPath = lookupPath // array keeps original path
318318
}
319319
} else {
320-
jsonPath = candidatePath
320+
jsonPath = lookupPath
321+
}
322+
elem.JsonPath = jsonPath
323+
// Array children use the item path
324+
if jsElements[lookupPath] != nil && jsElements[lookupPath].ElementType == "Array" {
325+
jsonPath = lookupPath + "|(Object)"
321326
}
322327
}
323-
elem.JsonPath = jsonPath
324328

325329
for _, child := range def.Children {
326330
elem.Children = append(elem.Children, buildExportMappingElementModel(moduleName, child, entity, jsonPath, jsElements, reader, false))

mdl/executor/cmd_import_mappings.go

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -281,24 +281,24 @@ func buildImportMappingElementModel(moduleName string, def *ast.ImportMappingEle
281281
var jsonPath string
282282
if isRoot {
283283
jsonPath = "(Object)"
284-
} else {
285-
jsonPath = parentPath + "|" + def.JsonName
286-
}
287-
elem.JsonPath = jsonPath
288-
289-
// Root must have empty ExposedName; children align with JSON structure
290-
if isRoot {
291284
elem.ExposedName = ""
292-
}
293-
294-
// Look up JSON structure element to align ExposedName and ElementType
295-
if info, ok := jsElements[jsonPath]; ok {
296-
if !isRoot {
285+
elem.JsonPath = jsonPath
286+
} else {
287+
// Look up by original JSON key, then use ExposedName for the mapping's JsonPath
288+
lookupPath := parentPath + "|" + def.JsonName
289+
if info, ok := jsElements[lookupPath]; ok {
297290
elem.ExposedName = info.ExposedName
291+
jsonPath = parentPath + "|" + info.ExposedName
292+
if info.ElementType == "Array" {
293+
elem.Kind = "Array"
294+
jsonPath = lookupPath // array container keeps original path
295+
}
296+
} else {
297+
jsonPath = lookupPath
298298
}
299-
if info.ElementType == "Array" {
300-
elem.Kind = "Array"
301-
// Children of array containers use the array item path
299+
elem.JsonPath = jsonPath
300+
// Array children use the item path for recursion
301+
if elem.Kind == "Array" {
302302
jsonPath = jsonPath + "|(Object)"
303303
}
304304
}
@@ -319,10 +319,13 @@ func buildImportMappingElementModel(moduleName string, def *ast.ImportMappingEle
319319
elem.Attribute = attr
320320

321321
// Compute JsonPath and align ExposedName with JSON structure
322-
jsonPath := parentPath + "|" + def.JsonName
323-
elem.JsonPath = jsonPath
324-
if info, ok := jsElements[jsonPath]; ok {
322+
// Look up by original JSON key path, then use ExposedName for the mapping's JsonPath
323+
lookupPath := parentPath + "|" + def.JsonName
324+
if info, ok := jsElements[lookupPath]; ok {
325325
elem.ExposedName = info.ExposedName
326+
elem.JsonPath = parentPath + "|" + info.ExposedName
327+
} else {
328+
elem.JsonPath = lookupPath
326329
}
327330
}
328331

0 commit comments

Comments
 (0)