-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReproducer.java
49 lines (40 loc) · 1.71 KB
/
Reproducer.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package test;
import jakarta.xml.bind.JAXBContext;
import jakarta.xml.bind.JAXBElement;
import jakarta.xml.bind.JAXBException;
import jakarta.xml.bind.Marshaller;
import jakarta.xml.bind.Unmarshaller;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import org.example.MyTestResultType;
import org.example.ObjectFactory;
public class Reproducer {
private static final ObjectFactory OF = new ObjectFactory();
private static JAXBContext getJaxbContext() {
try {
return JAXBContext.newInstance( OF.getClass() );
}
catch ( JAXBException ex ) {
throw new RuntimeException( ex );
}
}
public static void main(String[] args) throws JAXBException {
// -- create object
JAXBContext context = getJaxbContext();
MyTestResultType result = OF.createMyTestResultType();
MyTestResultType.Values values = OF.createMyTestResultTypeValues();
// values.getContent().add( "test" );
result.setValues( values );
JAXBElement<MyTestResultType> resultElemIn = OF.createMyTestResult( result );
// -- marshall
Marshaller marshaller = context.createMarshaller();
ByteArrayOutputStream os = new ByteArrayOutputStream();
marshaller.marshal( resultElemIn, os );
// -- unmarshall
ByteArrayInputStream is = new ByteArrayInputStream( os.toByteArray() );
Unmarshaller unmarshaller = context.createUnmarshaller();
JAXBElement<MyTestResultType> resultElemOut = (JAXBElement<MyTestResultType>) unmarshaller.unmarshal( is );
// -- print
// System.out.println( "finished: " + resultElemOut.getValue().getValues().getContent().get( 0 ) );
}
}