XmlElement(name="custom_name") not working in spring boot integrated with rest services
<p>I am almost new to rest services world,here i am trying to change the field name displayed in the output xml.</p>
<p>Not sure,am i following the right method,any help is a good thing.</p>
<p><strong>Activity.java</strong></p>

<pre><code>import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement
@XmlAccessorType(XmlAccessType.PROPERTY)
public class Activity {
    
    private int activityId;
    private int duration;
    private String  description;
    
    
    public Activity(int activityId, int duration, String description) {
        super();
        this.activityId = activityId;
        this.duration = duration;
        this.description = description;
    }
    
    @XmlElement(name=&quot;actvID&quot;)
    public int getActivityId() {
        return activityId;
    }
    public void setActivityId(int activityId) {
        this.activityId = activityId;
    }
    public int getDuration() {
        return duration;
    }
    public void setDuration(int duration) {
        this.duration = duration;
    }
    public String getDescription() {
        return description;
    }
    public void setDescription(String description) {
        this.description = description;
    }
    @Override
    public String toString() {
        return &quot;Activity [activityId=&quot; + activityId + &quot;, duration=&quot; + duration + &quot;, description=&quot; + description + &quot;]&quot;;
    }
}
</code></pre>
<p><strong>ActivityController.java</strong></p>

<pre><code>import java.util.List;
    
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
    
import com.rest.domains.Activity;
import com.rest.services.ActivityService;
    
@Controller
@RequestMapping(&quot;/activity&quot;)
public class ActivityController {
    
    private ActivityService activityService;
    
    @Autowired
    public void setActivityService(ActivityService activityService) {
        this.activityService = activityService;
    }
    
    @RequestMapping(value=&quot;/list&quot;, method=RequestMethod.GET, produces=MediaType.APPLICATION_XML_VALUE)
    @ResponseBody
    public List&lt;Activity&gt; getAllActivities(){
        return activityService.getAllActivities();
    }
}
</code></pre>
<p><strong>Current Output</strong></p>

<pre><code>&lt;List&gt;
    &lt;item&gt;
        &lt;activityId&gt;1&lt;/activityId&gt;
        &lt;duration&gt;10&lt;/duration&gt;
        &lt;description&gt;walking&lt;/description&gt;
    &lt;/item&gt;
    &lt;item&gt;
        &lt;activityId&gt;2&lt;/activityId&gt;
        &lt;duration&gt;20&lt;/duration&gt;
        &lt;description&gt;swimming&lt;/description&gt;
    &lt;/item&gt;
    &lt;item&gt;
        &lt;activityId&gt;3&lt;/activityId&gt;
        &lt;duration&gt;30&lt;/duration&gt;
        &lt;description&gt;gym&lt;/description&gt;
    &lt;/item&gt;
&lt;/List&gt;
</code></pre>
<p><strong>Expected output</strong></p>
<p><em><strong>Changes from activityId to actvID</strong></em></p>

<pre><code>&lt;List&gt;
    &lt;item&gt;
        &lt;actvID&gt;1&lt;/actvID&gt;
        &lt;duration&gt;10&lt;/duration&gt;
        &lt;description&gt;walking&lt;/description&gt;
    &lt;/item&gt;
    &lt;item&gt;
        &lt;actvID&gt;2&lt;/actvID&gt;
        &lt;duration&gt;20&lt;/duration&gt;
        &lt;description&gt;swimming&lt;/description&gt;
    &lt;/item&gt;
    &lt;item&gt;
        &lt;actvID&gt;3&lt;/actvID&gt;
        &lt;duration&gt;30&lt;/duration&gt;
        &lt;description&gt;gym&lt;/description&gt;
    &lt;/item&gt;
&lt;/List&gt;
</code></pre>