fixing issue on unmarshalling JSON
git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/data-analysis/dataminer-invocation-model@174721 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
321c58494b
commit
a82a4fdaf2
13
pom.xml
13
pom.xml
|
@ -60,21 +60,28 @@
|
|||
<dependency>
|
||||
<groupId>com.sun.xml.bind</groupId>
|
||||
<artifactId>jaxb-core</artifactId>
|
||||
<version>2.2.11</version>
|
||||
<version>2.3.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.sun.xml.bind</groupId>
|
||||
<artifactId>jaxb-impl</artifactId>
|
||||
<version>2.2.11</version>
|
||||
<version>2.3.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.glassfish</groupId>
|
||||
<artifactId>javax.json</artifactId>
|
||||
<version>1.1.2</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.eclipse.persistence</groupId>
|
||||
<artifactId>org.eclipse.persistence.moxy</artifactId>
|
||||
<version>2.5.2</version>
|
||||
<version>2.7.3</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
|
|
@ -20,7 +20,7 @@ import javax.xml.transform.stream.StreamSource;
|
|||
import javax.xml.validation.Schema;
|
||||
import javax.xml.validation.SchemaFactory;
|
||||
|
||||
import org.eclipse.persistence.jaxb.MarshallerProperties;
|
||||
import org.eclipse.persistence.jaxb.JAXBContextProperties;
|
||||
import org.gcube.data.analysis.dminvocation.model.DataMinerInvocation;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
|
@ -97,12 +97,15 @@ public class DataMinerInvocationManager {
|
|||
|
||||
switch (mediaType) {
|
||||
case ApplicationJSON:
|
||||
jaxbMarshaller.setProperty(MarshallerProperties.JSON_INCLUDE_ROOT, Boolean.TRUE);
|
||||
jaxbMarshaller.setProperty(JAXBContextProperties.JSON_INCLUDE_ROOT, true);
|
||||
jaxbMarshaller.setProperty(JAXBContextProperties.JSON_ATTRIBUTE_PREFIX, "@");
|
||||
break;
|
||||
case ApplicationXML:
|
||||
default:
|
||||
jaxbMarshaller.setProperty(MarshallerProperties.MEDIA_TYPE, mediaType.getMimeType());
|
||||
|
||||
}
|
||||
|
||||
jaxbMarshaller.setProperty(JAXBContextProperties.MEDIA_TYPE, mediaType.getMimeType());
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
jaxbMarshaller.marshal(dmInvocation, baos);
|
||||
return baos;
|
||||
|
@ -130,12 +133,14 @@ public class DataMinerInvocationManager {
|
|||
|
||||
switch (mediaType) {
|
||||
case ApplicationJSON:
|
||||
jaxbUnmarshaller.setProperty(MarshallerProperties.JSON_INCLUDE_ROOT, Boolean.TRUE);
|
||||
jaxbUnmarshaller.setProperty(JAXBContextProperties.JSON_INCLUDE_ROOT, true);
|
||||
jaxbUnmarshaller.setProperty(JAXBContextProperties.JSON_ATTRIBUTE_PREFIX, "@");
|
||||
break;
|
||||
case ApplicationXML:
|
||||
default:
|
||||
jaxbUnmarshaller.setProperty(MarshallerProperties.MEDIA_TYPE, mediaType.getMimeType());
|
||||
}
|
||||
|
||||
}
|
||||
jaxbUnmarshaller.setProperty(JAXBContextProperties.MEDIA_TYPE, mediaType.getMimeType());
|
||||
return (DataMinerInvocation) jaxbUnmarshaller.unmarshal(dmInvocationXMLStream);
|
||||
|
||||
}
|
||||
|
|
|
@ -33,7 +33,11 @@ import org.gcube.data.analysis.dminvocation.ActionType;
|
|||
@ToString
|
||||
public class DataMinerInvocation implements Serializable{
|
||||
|
||||
private static final long serialVersionUID = -3642902539322040226L;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 8506240125306265159L;
|
||||
|
||||
|
||||
@XmlElement(name = "operator-id", required=true, nillable=false)
|
||||
private String operatorId;
|
||||
|
|
|
@ -56,7 +56,7 @@ public class DataMinerInvocationTest {
|
|||
// DataMinerParameters params = new DataMinerParameters(inputParams, outputParams);
|
||||
|
||||
DataMinerInvocation dmInvocation = new DataMinerInvocation();
|
||||
dmInvocation.setOperatorId(operatorID);
|
||||
//dmInvocation.setOperatorId(operatorID);
|
||||
//dmInvocation.setParameters(params);
|
||||
System.out.println(dmInvocation);
|
||||
|
||||
|
@ -78,10 +78,14 @@ public class DataMinerInvocationTest {
|
|||
ByteArrayOutputStream outStreamJSON = dmMng.marshaling(dmInvocation, MediaType.ApplicationXML, true);
|
||||
System.out.println(new String(outStreamJSON.toByteArray()));
|
||||
|
||||
outStreamJSON = dmMng.marshaling(dmInvocation, MediaType.ApplicationJSON, true);
|
||||
System.out.println(new String(outStreamJSON.toByteArray()));
|
||||
|
||||
}
|
||||
|
||||
//@Test
|
||||
@Test
|
||||
public void unmarshallingJSONTest() throws JAXBException, IOException, SAXException{
|
||||
System.out.println(DataMinerInvocationTest.class.getMethods()[2].getName()+" called");
|
||||
FileInputStream dmInvocationJSONFile = new FileInputStream(new File("./src/test/resources/DataMinerInvocation.json"));
|
||||
DataMinerInvocation dmInvocation = dmMng.unmarshaling(dmInvocationJSONFile, MediaType.ApplicationJSON, true);
|
||||
System.out.println(dmInvocation);
|
||||
|
@ -90,4 +94,17 @@ public class DataMinerInvocationTest {
|
|||
System.out.println(new String(outStreamXML.toByteArray()));
|
||||
|
||||
}
|
||||
|
||||
// public static void main(String[] args) throws JAXBException, IOException, SAXException {
|
||||
// parameters.put("[key1]", "[value1]");
|
||||
// parameters.put("[key2]", "[value2]");
|
||||
// dmMng = DataMinerInvocationManager.getInstance();
|
||||
// System.out.println(DataMinerInvocationTest.class.getMethods()[2].getName()+" called");
|
||||
// FileInputStream dmInvocationJSONFile = new FileInputStream(new File("./src/test/resources/DataMinerInvocation.json"));
|
||||
// DataMinerInvocation dmInvocation = dmMng.unmarshaling(dmInvocationJSONFile, MediaType.ApplicationJSON, true);
|
||||
// System.out.println(dmInvocation);
|
||||
//
|
||||
// ByteArrayOutputStream outStreamXML = dmMng.marshaling(dmInvocation, MediaType.ApplicationXML, true);
|
||||
// System.out.println(new String(outStreamXML.toByteArray()));
|
||||
// }
|
||||
}
|
||||
|
|
|
@ -1,15 +1,17 @@
|
|||
{
|
||||
"dataminer-invocation" : {
|
||||
"operator-id" : "org.gcube.dataanalysis.wps.statisticalmanager.synchserver.mappedclasses.transducerers.MPA_INTERSECT",
|
||||
"action" : "RUN",
|
||||
"parameters" : {
|
||||
"input" : {
|
||||
"param" : [ {
|
||||
"param" : {
|
||||
"key" : "fileId",
|
||||
"value" : "http://publicLinkToFile"
|
||||
}, {
|
||||
},
|
||||
"param" : {
|
||||
"key" : "param2",
|
||||
"value" : "value2"
|
||||
} ]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue