Skip to content

Instantly share code, notes, and snippets.

@atskimura
Last active February 26, 2024 16:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atskimura/c4df118db5f7cc19772232182a8423cf to your computer and use it in GitHub Desktop.
Save atskimura/c4df118db5f7cc19772232182a8423cf to your computer and use it in GitHub Desktop.
public with sharing class ReservedKeywordsResult {
public String currency_x;
}
%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"}
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