-
-
Save atskimura/c4df118db5f7cc19772232182a8423cf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public with sharing class ReservedKeywordsResult { | |
public String currency_x; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%dw 2.0 | |
input incomingJson application/json | |
output application/apex | |
fun renameKey(key: Key) = key match { | |
case "private" -> "isPrivate" | |
case "object" -> "obj" | |
case "currency" -> "currency_x" | |
else -> (key) | |
} | |
--- | |
incomingJson map (record) -> ( | |
record mapObject (value, key, index) -> { | |
(renameKey(key)) : value | |
} | |
) as Object {class: "ReservedKeywordsResult"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String jsonString = '[{"currency" : "ABC"}]'; | |
DataWeave.Script script = new DataWeaveScriptResource.reservedKeywordsToObject(); | |
DataWeave.Result result = script.execute(new Map<String, Object>{ 'incomingJson' => jsonString }); | |
List<ReservedKeywordsResult> results = (List<ReservedKeywordsResult>) result.getValue(); | |
System.debug(results); | |
Assert.areEqual(1, results.size()); | |
ReservedKeywordsResult res = results[0]; | |
system.debug(res); | |
Assert.areEqual('ABC', res.currency_x); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment