2014-10-20 2 views
0

나는이 객체에 사용자 주소 정보를 저장하고 Storein을 저장하는 간단한 스프링 웹 애플리케이션을 구축하고있다. 이 ContactInfo는 데이터베이스에 행을 삽입하는 웹 서비스로 전달됩니다 ..자바 객체를 자바 xml 객체로 변환하기

Contactinfo.

내가 웹 응용 프로그램과 웹 서비스를 구축하고있어 이후
public class ContactInfo { 
    String addr1; 
    String addr2; 
    String city; 
    String state; 
    String pin; 
    String country; 
    String phone; 
    String mobile; 
    String email; 
} 

, 내 웹 서비스에 CONTACTINFO을 재사용하기 위해 노력하고있어 ... 그래서, 내 서비스는 다음과 같습니다 -

@WebService 
@SOAPBinding(style = SOAPBinding.Style.RPC) 
public class HelloWebService{ 
    @WebMethod(operationName = "sayHello") 
    public String sayHello(@WebParam(name="guestname") Contactinfo contactinfo){ 
     return "Hello "; 

    } 
} 

및 생성 된 WSDL CONTACTINFO 클래스는 다음과 같습니다 -

@XmlAccessorType(XmlAccessType.FIELD) 
@XmlType(name = "contactInfo", propOrder = { 
    "addr1", 
    "addr2", 
    "city", 
    "country", 
    "email", 
    "mobile", 
    "phone", 
    "pin", 
    "state" 
}) 
public class ContactInfo { 

    protected String addr1; 
    protected String addr2; 
    protected String city; 
    protected String country; 
    protected String email; 
    protected String mobile; 
    protected String phone; 
    protected String pin; 
    protected String state; 

    /** 
    * Gets the value of the addr1 property. 
    * 
    * @return 
    *  possible object is 
    *  {@link String } 
    *  
    */ 
    public String getAddr1() { 
     return addr1; 
    } 

    /** 
    * Sets the value of the addr1 property. 
    * 
    * @param value 
    *  allowed object is 
    *  {@link String } 
    *  
    */ 
    public void setAddr1(String value) { 
     this.addr1 = value; 
    } 

    /** 
    * Gets the value of the addr2 property. 
    * 
    * @return 
    *  possible object is 
    *  {@link String } 
    *  
    */ 
    public String getAddr2() { 
     return addr2; 
    } 

    /** 
    * Sets the value of the addr2 property. 
    * 
    * @param value 
    *  allowed object is 
    *  {@link String } 
    *  
    */ 
    public void setAddr2(String value) { 
     this.addr2 = value; 
    } 

    /** 
    * Gets the value of the city property. 
    * 
    * @return 
    *  possible object is 
    *  {@link String } 
    *  
    */ 
    public String getCity() { 
     return city; 
    } 

    /** 
    * Sets the value of the city property. 
    * 
    * @param value 
    *  allowed object is 
    *  {@link String } 
    *  
    */ 
    public void setCity(String value) { 
     this.city = value; 
    } 

    /** 
    * Gets the value of the country property. 
    * 
    * @return 
    *  possible object is 
    *  {@link String } 
    *  
    */ 
    public String getCountry() { 
     return country; 
    } 

    /** 
    * Sets the value of the country property. 
    * 
    * @param value 
    *  allowed object is 
    *  {@link String } 
    *  
    */ 
    public void setCountry(String value) { 
     this.country = value; 
    } 

    /** 
    * Gets the value of the email property. 
    * 
    * @return 
    *  possible object is 
    *  {@link String } 
    *  
    */ 
    public String getEmail() { 
     return email; 
    } 

    /** 
    * Sets the value of the email property. 
    * 
    * @param value 
    *  allowed object is 
    *  {@link String } 
    *  
    */ 
    public void setEmail(String value) { 
     this.email = value; 
    } 

    /** 
    * Gets the value of the mobile property. 
    * 
    * @return 
    *  possible object is 
    *  {@link String } 
    *  
    */ 
    public String getMobile() { 
     return mobile; 
    } 

    /** 
    * Sets the value of the mobile property. 
    * 
    * @param value 
    *  allowed object is 
    *  {@link String } 
    *  
    */ 
    public void setMobile(String value) { 
     this.mobile = value; 
    } 

    /** 
    * Gets the value of the phone property. 
    * 
    * @return 
    *  possible object is 
    *  {@link String } 
    *  
    */ 
    public String getPhone() { 
     return phone; 
    } 

    /** 
    * Sets the value of the phone property. 
    * 
    * @param value 
    *  allowed object is 
    *  {@link String } 
    *  
    */ 
    public void setPhone(String value) { 
     this.phone = value; 
    } 

    /** 
    * Gets the value of the pin property. 
    * 
    * @return 
    *  possible object is 
    *  {@link String } 
    *  
    */ 
    public String getPin() { 
     return pin; 
    } 

    /** 
    * Sets the value of the pin property. 
    * 
    * @param value 
    *  allowed object is 
    *  {@link String } 
    *  
    */ 
    public void setPin(String value) { 
     this.pin = value; 
    } 

    /** 
    * Gets the value of the state property. 
    * 
    * @return 
    *  possible object is 
    *  {@link String } 
    *  
    */ 
    public String getState() { 
     return state; 
    } 

    /** 
    * Sets the value of the state property. 
    * 
    * @param value 
    *  allowed object is 
    *  {@link String } 
    *  
    */ 
    public void setState(String value) { 
     this.state = value; 
    } 

} 

를 자, 내가 (A XML 객체를 필요로하는) ​​내 웹 서비스에 CONTACTINFO (일반 POJO 객체)를 전달할 수있는 방법을 알아야합니다 ..

내가 XML과 반대하지만 자바 XML 객체에 POJO 객체를 변환하는 것도 자바 객체를 변환하는 블로그를 참조

...

+0

나는 당신의 질문에 대해 확실하지 않다. 이 웹 서비스 (원격 시스템에서 가능)를 호출하는 방법을 알고 싶습니까? –

+0

아니요, 웹 서비스를 호출 할 수 있습니다. Java POJO 객체를 XML 파일로 변환하지 않고 Java XML 객체로 변환해야합니다. – user1050619

+0

Java XML 객체 란 무엇입니까? ContactInfo 객체의 문자열 표현을 의미합니까? – mendieta

답변

0

당신은 도저 프레임 워크를 사용할 수 있습니다 (http://dozer.sourceforge.net/) ..

그것은 제공 당신은 API는

예 (유사한 구조를 가진)으로부터 다른 객체를 생성합니다 :

Mapper mapper = new DozerBeanMapper(); 

DestinationObject destObject = new DestinationObject(); 
mapper.map(sourceObject, destObject); 
+1

고마워요. 내가 뭘 찾고 있었는지 ... anyones 참조를위한 기사도 찾았습니다. - http://www.javaworld.com/article/2074949/core-java/dozer--mapping-jaxb-objects-to-business-domain-objects.html – user1050619

관련 문제