2017-11-21 7 views

答えて

2

あなたのCountryタイプのカスタム@XmlJavaTypeAdapterを作成することができます。

public static class CountryXmlAdapter extends XmlAdapter<String, Country> { 

    @Override 
    public Country unmarshal(String v) throws Exception { 
     Country c = new Country(); 
     c.setName(v); 
     return c; 
    } 

    @Override 
    public String marshal(Country v) throws Exception { 
     return v != null ? v.getName() : null; 
    } 
} 

その後、あなたは、単にそのようなあなたの国フィールドに注釈を付ける:

@Entity 
@XmlRootElement 
public class test { 
    @Getter 
    @Setter 
    @XmlElement(name = "country") 
    @XmlJavaTypeAdapter(CountryXmlAdapter.class) 
    private Country country 
} 

それとも、あなたが心配している場合の片道のみのマーシャリングtestクラスにメソッドgetCountryName()を作成し、@XmlElementと注釈を付けてみてください。

関連する問題