Skip to content

Instantly share code, notes, and snippets.

@drexler
Last active September 13, 2017 18:51
Show Gist options
  • Save drexler/9e3d1b4badfe78b34b03a1f099a6013f to your computer and use it in GitHub Desktop.
Save drexler/9e3d1b4badfe78b34b03a1f099a6013f to your computer and use it in GitHub Desktop.
Test for a property existence in a velocity template
{
#set($flag = false)
#set($missing = "'""""'")
#if("'$input.json('$.aJsonField')'" != $missing)
"JsonFieldIsPresent": $input.json('$.aJsonField')
#set($flag = true)
#end
#if("'$input.json('$.aJsonField')'" == $missing)
#if($flag == true), #end
"JsonFieldIsMissing": true
#end
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment