Skip to content

Instantly share code, notes, and snippets.

@stoicflame
Created March 16, 2015 16:56
Show Gist options
  • Save stoicflame/57252b7b04daa65195bf to your computer and use it in GitHub Desktop.
Save stoicflame/57252b7b04daa65195bf to your computer and use it in GitHub Desktop.
package org.codehaus.enunciate.domain.login;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.annotation.XmlRootElement;
import java.io.StringReader;
/**
* @author Ryan Heaton
*/
@XmlRootElement
public class LoginRequest {
public String organizationName;
public String password;
public String username;
public static void main(String[] args) throws Exception {
LoginRequest sampleRequest = new LoginRequest();
sampleRequest.organizationName = "organization";
sampleRequest.password = "password";
sampleRequest.username = "username";
//outputs: <?xml version="1.0" encoding="UTF-8" standalone="yes"?><ns2:loginRequest xmlns:ns2="http://www.ncr.com/app1/ns1"><organizationName>organization</organizationName><password>password</password><username>username</username></ns2:loginRequest>
JAXBContext context = JAXBContext.newInstance(LoginRequest.class);
context.createMarshaller().marshal(sampleRequest, System.out);
String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><loginRequest xmlns=\"http://www.ncr.com/app1/ns1\"><organizationName xmlns=\"\">organization</organizationName><password xmlns=\"\">password</password><username xmlns=\"\">username</username></loginRequest>";
sampleRequest = (LoginRequest) context.createUnmarshaller().unmarshal(new StringReader(xml));
assert sampleRequest.username.equals("username");
assert sampleRequest.password.equals("password");
assert sampleRequest.organizationName.equals("organization");
}
}
@XmlSchema (
namespace = "http://www.ncr.com/app1/ns1"
)
package org.codehaus.enunciate.domain.login;
import javax.xml.bind.annotation.XmlSchema;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment