Including JAXB annotation into getter method generation

已回答

Hi,

I am trying to create a getter template to have get methods already JAXB annotated but I am getting an error which doesn't make any sense.

The error message is showing the final output which is correct, but intellij thinks it is not right and it does not add it to the class.

here is my template:

#if($field.collection)
#if ($StringUtil.endsWithIgnoreCase($field.name,"History"))
@XmlElement(name="$StringUtil.trimEnd($field.name, "History")")
#elseif($StringUtil.endsWithIgnoreCase($field.name,"ies"))
@XmlElement(name="$StringUtil.trimEnd($field.name, "ies")##
y")
#elseif ($StringUtil.endsWithIgnoreCase($field.name,"s"))
@XmlElement(name="$StringUtil.trimEnd($field.name, "s")")
#else
@XmlElement(name="$field.name")
#end
#else
@XmlElement(name="$field.name")
#end
#if($field.collection)
@XmlElementWrapper(name="$field.name")
#end
#if($field.modifierStatic)
static ##
#end
$field.type ##
#set($name = $StringUtil.capitalizeWithJavaBeanConvention($StringUtil.sanitizeJavaIdentifier($helper.getPropertyName($field, $project))))
#if ($field.boolean && $field.primitive)
is##
#else
get##
#end
${name}() {
return $field.name;
}
0

Please attach idea.log (Help|Show log). Thanks

0
Avatar
Permanently deleted user

I just checked and unfortunately there is nothing in the logs about this.

Apparently the template is not working if I use it with collections. In my case I have a collection called programOfferingHistory.

As you can see the output is correct. However, if I apply the same template to any other variable which is not a collection it will work fine.

I also tried to modify the template to make it working and if I exclude the first part and I add both the XmlElement and XmlElementWrapper with the same name without cutting "History" it works.

so the issue is that intellij is thinking @XmlElementWrapper(name="programOffering") is not correct while it is. The issue is only in the string assigned to name.

0

There is leading space, could you please eliminate it?

0
Avatar
Permanently deleted user

It works!!!!! awesome! thank you!

0

请先登录再写评论。