FranzGames / google-gson

Automatically exported from code.google.com/p/google-gson
0 stars 0 forks source link

Example/Enhancement: using XmlElement annotation for naming fields #508

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
jaxws wsimport generates pojo java classes from wsdl using a
@XmlElement(name="{name}", ...) annotation. The following custom naming 
strategy uses this annotation:
/**
 *      XmlElement annotation to get the field name
 *      @XmlElement(name = "{name}")
 */
public class XmlElementFieldNamingPolicy implements FieldNamingStrategy {
    /**
     * @param   f       field
     * @return name of XmlElement annotation if field has XmlElement annotation
     */
    @Override
    public String translateName(Field f) {
        XmlElement v_annotation = f.getAnnotation(XmlElement.class);
        return v_annotation != null ? v_annotation.name() : f.getName();
    }
}

Original issue reported on code.google.com by mbreuer....@googlemail.com on 25 Mar 2013 at 9:51