Skip to content

Instantly share code, notes, and snippets.

@bholota
Created December 14, 2016 15:28
Show Gist options
  • Save bholota/e234b69eb8f27a048519fd1be7224da8 to your computer and use it in GitHub Desktop.
Save bholota/e234b69eb8f27a048519fd1be7224da8 to your computer and use it in GitHub Desktop.
InteliJ getter/setter template for Jackson properties
// JacksonGetter
#set($const_name = $helper.getPropertyName($field, $project).toString().replaceAll("([A-Z]+)","\_$1").toUpperCase())
@JsonProperty(${const_name})
@Nullable
#if($field.modifierStatic)
static ##
#end
$field.type ##
#set($name = $StringUtil.capitalizeWithJavaBeanConvention($StringUtil.sanitizeJavaIdentifier($helper.getPropertyName($field, $project))))
#if ($field.boolean && $field.primitive)
#if ($StringUtil.startsWithIgnoreCase($name, 'is'))
#set($name = $StringUtil.decapitalize($name))
#else
is##
#end
#else
get##
#end
${name}() {
return $field.name;
}
// JacksonSetter
#set($const_name = $helper.getPropertyName($field, $project).toString().replaceAll("([A-Z]+)","\_$1").toUpperCase())
@JsonProperty(${const_name})
#set($paramName = $helper.getParamName($field, $project))
#if($field.modifierStatic)
static ##
#end
void set$StringUtil.capitalizeWithJavaBeanConvention($StringUtil.sanitizeJavaIdentifier($helper.getPropertyName($field, $project)))($field.type $paramName) {
#if ($field.name == $paramName)
#if (!$field.modifierStatic)
this.##
#else
$classname.##
#end
#end
$field.name = $paramName;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment