I'm using Gson provided by google

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/data-analysis/dataminer-invocation-model@176008 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2018-12-19 11:23:15 +00:00
parent e28d0a4c94
commit d95591219e
13 changed files with 278 additions and 251 deletions

14
pom.xml
View File

@ -80,9 +80,10 @@
</dependency>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.json</artifactId>
<version>1.1.2</version>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.5</version>
<scope>compile</scope>
</dependency>
<dependency>
@ -127,6 +128,13 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>

View File

@ -0,0 +1,35 @@
/**
*
*/
package org.gcube.data.analysis.dminvocation;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import org.gcube.data.analysis.dminvocation.model.DataMinerInvocation;
import com.google.gson.annotations.SerializedName;
/**
* The Class DataMinerInvocationJSONWrapper.
* Used only to add the root name "dataminer-invocation" in the JSON
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
* Dec 19, 2018
*/
@AllArgsConstructor
@NoArgsConstructor
@Getter
@Setter
@ToString
public class DataMinerInvocationJSONWrapper {
@SerializedName("dataminer-invocation")
private DataMinerInvocation dataminerInvocation;
}

View File

@ -3,10 +3,15 @@
*/
package org.gcube.data.analysis.dminvocation;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import javax.xml.XMLConstants;
import javax.xml.bind.JAXBContext;
@ -24,6 +29,10 @@ import org.eclipse.persistence.jaxb.JAXBContextProperties;
import org.gcube.data.analysis.dminvocation.model.DataMinerInvocation;
import org.xml.sax.SAXException;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonSyntaxException;
/**
@ -78,70 +87,74 @@ public class DataMinerInvocationManager {
* Marshaling.
*
* @param dmInvocation the dm invocation
* @param mediaType the media type see at {@link MediaType}
* @param validateModel the validate model. If true performs model validation against the xml schema generated for {@link DataMinerInvocation}
* @return the byte array output stream
* @return the marshal XML
* @throws JAXBException the JAXB exception
*/
public ByteArrayOutputStream marshaling(DataMinerInvocation dmInvocation, MediaType mediaType, boolean validateModel) throws JAXBException
public String marshalingXML(DataMinerInvocation dmInvocation, boolean validateModel) throws JAXBException
{
Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
if(validateModel)
jaxbMarshaller.setSchema(schema);
jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
if(mediaType==null)
mediaType = MediaType.ApplicationXML;
switch (mediaType) {
case ApplicationJSON:
jaxbMarshaller.setProperty(JAXBContextProperties.JSON_INCLUDE_ROOT, true);
jaxbMarshaller.setProperty(JAXBContextProperties.JSON_ATTRIBUTE_PREFIX, "@");
break;
case ApplicationXML:
default:
}
jaxbMarshaller.setProperty(JAXBContextProperties.MEDIA_TYPE, mediaType.getMimeType());
jaxbMarshaller.setProperty(JAXBContextProperties.MEDIA_TYPE, MediaType.ApplicationXML.getMimeType());
ByteArrayOutputStream baos = new ByteArrayOutputStream();
jaxbMarshaller.marshal(dmInvocation, baos);
return baos;
return new String(baos.toByteArray());
}
/**
* Unmarshaling.
* Marshaling json.
*
* @param dmInvocation the dm invocation
* @return the marshal JSON
* @throws JAXBException the JAXB exception
*/
public String marshalingJSON(DataMinerInvocation dmInvocation) throws JAXBException
{
Gson gson = new GsonBuilder().setPrettyPrinting().create();
DataMinerInvocationJSONWrapper wrapper = new DataMinerInvocationJSONWrapper(dmInvocation);
return gson.toJson(wrapper);
}
/**
* Unmarshaling xml.
*
* @param dmInvocationIS the dm invocation input stream
* @param mediaType the media type see at {@link MediaType}
* @param validateModel the validate model. If true performs model validation against the xml schema generated for {@link DataMinerInvocation}
* @return the data miner invocation
* @throws JAXBException the JAXB exception
* @throws IOException Signals that an I/O exception has occurred.
*/
public DataMinerInvocation unmarshaling(InputStream dmInvocationIS, MediaType mediaType, boolean validateModel) throws JAXBException
{
public DataMinerInvocation unmarshalingXML(InputStream dmInvocationIS, boolean validateModel) throws JAXBException, IOException {
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
if(validateModel)
jaxbUnmarshaller.setSchema(schema);
if(mediaType==null)
mediaType = MediaType.ApplicationXML;
switch (mediaType) {
case ApplicationJSON:
jaxbUnmarshaller.setProperty(JAXBContextProperties.JSON_INCLUDE_ROOT, true);
jaxbUnmarshaller.setProperty(JAXBContextProperties.JSON_ATTRIBUTE_PREFIX, "@");
break;
case ApplicationXML:
default:
}
jaxbUnmarshaller.setProperty(JAXBContextProperties.MEDIA_TYPE, mediaType.getMimeType());
jaxbUnmarshaller.setProperty(JAXBContextProperties.MEDIA_TYPE, MediaType.ApplicationXML.getMimeType());
return (DataMinerInvocation) jaxbUnmarshaller.unmarshal(dmInvocationIS);
}
/**
* Unmarshaling json.
*
* @param dmInvocationIS the dm invocation is
* @return the data miner invocation
* @throws JsonSyntaxException the json syntax exception
* @throws IOException Signals that an I/O exception has occurred.
*/
public DataMinerInvocation unmarshalingJSON(InputStream dmInvocationIS) throws JsonSyntaxException, IOException {
String json = convertToString(dmInvocationIS);
Gson gson = new Gson();
DataMinerInvocationJSONWrapper wrapper = gson.fromJson(json, DataMinerInvocationJSONWrapper.class);
return wrapper.getDataminerInvocation();
}
@ -202,4 +215,24 @@ public class DataMinerInvocationManager {
return schemaOutputStream.toByteArray();
}
}
/**
* Convert to string.
*
* @param inputStream the input stream
* @return the string
* @throws IOException Signals that an I/O exception has occurred.
*/
public String convertToString(InputStream inputStream)throws IOException {
StringBuilder textBuilder = new StringBuilder();
try (Reader reader = new BufferedReader(new InputStreamReader(inputStream, Charset.forName(StandardCharsets.UTF_8.name())))) {
int c = 0;
while ((c = reader.read()) != -1) {
textBuilder.append((char) c);
}
}
return textBuilder.toString();
}
}

View File

@ -28,7 +28,7 @@ public class DataMinerParamListAdaptor extends XmlAdapter<DataMinerParamList, Li
public List<DataMinerParam> unmarshal(DataMinerParamList list) throws Exception{
System.out.println("Unmarshal called: ");
List<DataMinerParam> retVal = new ArrayList<DataMinerParam>();
for (DataMinerParam dmp : list.getValues()){
for (DataMinerParam dmp : list.getListParam()){
System.out.println("key: "+dmp.getKey()+" value: "+ dmp.getValue());
retVal.add(new DataMinerParam(dmp.getKey(), dmp.getValue()));
}
@ -48,7 +48,7 @@ public class DataMinerParamListAdaptor extends XmlAdapter<DataMinerParamList, Li
// System.out.println("key: "+dmp.getKey()+" value: "+ dmp.getValue());
// values.add(new DataMinerParam(dmp.getKey(), dmp.getValue()));
// }
retVal.setValues(list);
retVal.setListParam(list);
return retVal;
}
}

View File

@ -1,51 +0,0 @@
///**
// *
// */
//package org.gcube.data.analysis.dminvocation;
//
//import java.util.HashMap;
//import java.util.Map;
//
//import javax.xml.bind.annotation.adapters.XmlAdapter;
//
//import org.gcube.data.analysis.dminvocation.model.DataMinerParam;
//import org.gcube.data.analysis.dminvocation.model.DataMinerParamList;
//
//
///**
// * The Class MapAdaptor.
// *
// * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
// * Dec 18, 2018
// */
//public class MapAdaptor extends XmlAdapter<DataMinerParamList, Map<String, String>>
//{
//
// /* (non-Javadoc)
// * @see javax.xml.bind.annotation.adapters.XmlAdapter#unmarshal(java.lang.Object)
// */
// @Override
// public Map<String, String> unmarshal(DataMinerParamList list) throws Exception{
// System.out.println("Unmarshal called: ");
// Map<String, String> retVal = new HashMap<String, String>();
// for (DataMinerParam keyValue : list.getValues()){
// System.out.println("key: "+keyValue.getKey()+" value: "+ keyValue.getValue());
// retVal.put(keyValue.getKey(), keyValue.getValue());
// }
// return retVal;
// }
//
// /* (non-Javadoc)
// * @see javax.xml.bind.annotation.adapters.XmlAdapter#marshal(java.lang.Object)
// */
// @Override
// public DataMinerParamList marshal(Map<String, String> map) throws Exception{
// System.out.println("Marshal called: ");
// DataMinerParamList retVal = new DataMinerParamList();
// for (String key : map.keySet()){
// System.out.println("key: "+key+" value: "+ map.get(key));
// retVal.getValues().add(new DataMinerParam(key, map.get(key)));
// }
// return retVal;
// }
//}

View File

@ -0,0 +1,49 @@
/**
*
*/
package org.gcube.data.analysis.dminvocation;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
import org.gcube.data.analysis.dminvocation.model.DataMinerInvocation;
import com.google.gson.Gson;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
/**
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Dec 19, 2018
*/
public class MyDeserializer implements JsonDeserializer<DataMinerInvocation> {
List<String> requiredFields = new ArrayList<String>();
void registerRequiredField(String fieldName) {
requiredFields.add(fieldName);
}
/* (non-Javadoc)
* @see com.google.gson.JsonDeserializer#deserialize(com.google.gson.JsonElement, java.lang.reflect.Type, com.google.gson.JsonDeserializationContext)
*/
@Override
public DataMinerInvocation deserialize(
JsonElement json, Type arg1, JsonDeserializationContext arg2)
throws JsonParseException {
JsonObject jsonObject = (JsonObject) json;
for (String fieldName : requiredFields) {
if (jsonObject.get(fieldName) == null) {
throw new JsonParseException("Required Field Not Found: " +
fieldName);
}
}
return new Gson().fromJson(json, DataMinerInvocation.class);
}
}

View File

@ -1,51 +0,0 @@
///**
// *
// */
//package org.gcube.data.analysis.dminvocation.model;
//
//import java.io.Serializable;
//import java.util.List;
//
//import javax.xml.bind.annotation.XmlAccessType;
//import javax.xml.bind.annotation.XmlAccessorType;
//import javax.xml.bind.annotation.XmlElement;
//import javax.xml.bind.annotation.XmlRootElement;
//
//import lombok.AllArgsConstructor;
//import lombok.Getter;
//import lombok.NoArgsConstructor;
//import lombok.Setter;
//import lombok.ToString;
//
//import com.fasterxml.jackson.annotation.JsonProperty;
//
//
///**
// * The Class DataMinerInputParams.
// *
// * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
// * Dec 4, 2018
// */
//@XmlRootElement(name = "dataminer-inputparams")
//@XmlAccessorType (XmlAccessType.FIELD)
////@JsonIgnoreProperties(ignoreUnknown=true)
//@NoArgsConstructor
//@AllArgsConstructor
//@Getter
//@Setter
//@ToString
//public class DataMinerInputParams implements Serializable{
//
// /**
// *
// */
// private static final long serialVersionUID = -7241629940190729604L;
//
// @XmlElement(name = "param", required=true, nillable=false)
// @JsonProperty(value="param", required=true)
// private List<DataMinerParam> listParam;
//
//
//
//
//}

View File

@ -18,9 +18,8 @@ import lombok.ToString;
import org.gcube.data.analysis.dminvocation.ActionType;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonRootName;
import com.google.gson.annotations.SerializedName;
/**
* The Class DataMinerInvocation.
@ -29,9 +28,7 @@ import com.fasterxml.jackson.annotation.JsonRootName;
* Dec 4, 2018
*/
@XmlRootElement(name = "dataminer-invocation")
@JsonRootName(value = "dataminer-invocation")
@XmlAccessorType (XmlAccessType.FIELD)
@JsonIgnoreProperties(ignoreUnknown=true)
@NoArgsConstructor
@AllArgsConstructor
@Getter
@ -46,15 +43,17 @@ public class DataMinerInvocation implements Serializable{
@XmlElement(name = "operator-id", required=true, nillable=false)
@JsonProperty(value="operator-id", required=true)
@JsonProperty(required = true)
@SerializedName(value="operator-id")
private String operatorId;
@XmlElement(name = "action", required=true, nillable=false)
@JsonProperty(value="action", required=true)
@JsonProperty(required = true)
@SerializedName(value="action")
private ActionType actionType = ActionType.RUN;
@XmlElement(name = "parameters", required=false, nillable=false)
@JsonProperty(required=false)
@JsonProperty(required = false)
@SerializedName(value="parameters")
private DataMinerParameters parameters;
}

View File

@ -1,48 +0,0 @@
///**
// *
// */
//package org.gcube.data.analysis.dminvocation.model;
//
//import java.io.Serializable;
//import java.util.List;
//
//import javax.xml.bind.annotation.XmlAccessType;
//import javax.xml.bind.annotation.XmlAccessorType;
//import javax.xml.bind.annotation.XmlElement;
//import javax.xml.bind.annotation.XmlRootElement;
//
//import lombok.AllArgsConstructor;
//import lombok.Getter;
//import lombok.NoArgsConstructor;
//import lombok.Setter;
//import lombok.ToString;
//
//import com.fasterxml.jackson.annotation.JsonProperty;
//
//
///**
// * The Class DataMinerOutputParams.
// *
// * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
// * Dec 4, 2018
// */
//@XmlRootElement(name = "dataminer-outputparams")
//@XmlAccessorType (XmlAccessType.FIELD)
////@JsonIgnoreProperties(ignoreUnknown=true)
//@NoArgsConstructor
//@AllArgsConstructor
//@Getter
//@Setter
//@ToString
//public class DataMinerOutputParams implements Serializable{
//
// /**
// *
// */
// private static final long serialVersionUID = -683773454747370184L;
//
// @XmlElement(name = "param", required=false, nillable=false)
// @JsonProperty(value="param", required=true)
// private List<DataMinerParam> params;
//
//}

View File

@ -4,6 +4,7 @@
package org.gcube.data.analysis.dminvocation.model;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
@ -17,8 +18,8 @@ import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.gson.annotations.SerializedName;
/**
@ -29,7 +30,6 @@ import com.fasterxml.jackson.annotation.JsonProperty;
*/
@XmlAccessorType (XmlAccessType.FIELD)
@XmlRootElement(name = "dataminer-param-list")
@JsonIgnoreProperties(ignoreUnknown=true)
@NoArgsConstructor
@AllArgsConstructor
@Getter
@ -43,6 +43,7 @@ public class DataMinerParamList implements Serializable{
private static final long serialVersionUID = 623106816934429133L;
@XmlElement(name = "param", required=true, nillable=false)
@JsonProperty(value="param", required=true)
private List<DataMinerParam> values;
@JsonProperty(required = true)
@SerializedName(value="param")
private List<DataMinerParam> listParam = new ArrayList<>();
}

View File

@ -1,6 +1,7 @@
/**
*
*/
package org.gcube.data.analysis.dminvocation.model;
import java.io.Serializable;
@ -18,33 +19,32 @@ import lombok.ToString;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.gson.annotations.SerializedName;
/**
* The Class DataMinerParameters.
*
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
* Dec 4, 2018
* Dec 4, 2018
*/
@XmlRootElement(name = "dataminer-parameters")
@XmlAccessorType (XmlAccessType.FIELD)
@JsonIgnoreProperties(ignoreUnknown=true)
@XmlAccessorType(XmlAccessType.FIELD)
@JsonIgnoreProperties(ignoreUnknown = true)
@NoArgsConstructor
@AllArgsConstructor
@Getter
@Setter
@ToString
public class DataMinerParameters implements Serializable{
public class DataMinerParameters implements Serializable {
private static final long serialVersionUID = 8298755690515099551L;
@XmlElement(name = "input", required=true, nillable=false)
@JsonProperty(required=true)
//@XmlJavaTypeAdapter(value = DataMinerParamListAdaptor.class)
@XmlElement(name = "input", required = true, nillable = false)
@JsonProperty(required = true)
@SerializedName(value = "input")
private DataMinerParamList input;
@XmlElement(name = "output", required=false, nillable=false)
@JsonProperty(required=false)
@XmlElement(name = "output", required = false, nillable = false)
@JsonProperty(required = false)
@SerializedName(value = "output")
private DataMinerParamList output;
}

View File

@ -3,7 +3,6 @@
*/
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
@ -14,8 +13,10 @@ import java.util.Map;
import javax.xml.bind.JAXBException;
import org.apache.commons.io.IOUtils;
import org.eclipse.persistence.jaxb.JAXBContext;
import org.gcube.data.analysis.dminvocation.DataMinerInvocationJSONWrapper;
import org.gcube.data.analysis.dminvocation.DataMinerInvocationManager;
import org.gcube.data.analysis.dminvocation.MediaType;
import org.gcube.data.analysis.dminvocation.model.DataMinerInvocation;
import org.gcube.data.analysis.dminvocation.model.DataMinerParam;
import org.gcube.data.analysis.dminvocation.model.DataMinerParamList;
@ -24,6 +25,9 @@ import org.junit.Before;
import org.junit.Test;
import org.xml.sax.SAXException;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
/**
*
@ -47,9 +51,9 @@ public class DataMinerInvocationTest {
}
@Test
//@Test
public void marshallingTest() throws JAXBException, IOException, SAXException {
System.out.println(DataMinerInvocationTest.class.getMethods()[0].getName()+" called");
System.out.println("marshallingTest called");
//LOADING PARAMETERS
List<DataMinerParam> inParams = new ArrayList<DataMinerParam>();
for (String pm : parameters.keySet()) {
@ -71,40 +75,44 @@ public class DataMinerInvocationTest {
// ByteArrayOutputStream outStreamJSON = DataMinerInvocationManager.marshaling(dmInvocation, MediaType.ApplicationJSON);
// System.out.println(new String(outStreamJSON.toByteArray()));
ByteArrayOutputStream outStreamXML = dmMng.marshaling(dmInvocation, MediaType.ApplicationXML, true);
System.out.println(new String(outStreamXML.toByteArray()));
String marshXML = dmMng.marshalingXML(dmInvocation, true);
System.out.println(marshXML);
ByteArrayOutputStream outStreamJSON = dmMng.marshaling(dmInvocation, MediaType.ApplicationJSON, true);
System.out.println(new String(outStreamJSON.toByteArray()));
String marshJSON = dmMng.marshalingJSON(dmInvocation);
System.out.println(marshJSON);
}
@Test
public void unmarshallingXMLTest() throws JAXBException, IOException, SAXException{
System.out.println(DataMinerInvocationTest.class.getMethods()[1].getName()+" called");
System.out.println("unmarshallingXMLTest called");
FileInputStream dmInvocationXMLFile = new FileInputStream(new File("./src/test/resources/DataMinerInvocation.xml"));
DataMinerInvocation dmInvocation = dmMng.unmarshaling(dmInvocationXMLFile, MediaType.ApplicationXML, true);
DataMinerInvocation dmInvocation = dmMng.unmarshalingXML(dmInvocationXMLFile, true);
System.out.println(dmInvocation);
ByteArrayOutputStream outStreamJSON = dmMng.marshaling(dmInvocation, MediaType.ApplicationXML, true);
System.out.println(new String(outStreamJSON.toByteArray()));
String marshXML = dmMng.marshalingXML(dmInvocation, true);
System.out.println(marshXML);
//
outStreamJSON = dmMng.marshaling(dmInvocation, MediaType.ApplicationJSON, true);
System.out.println(new String(outStreamJSON.toByteArray()));
String marshJSON = dmMng.marshalingJSON(dmInvocation);
System.out.println(marshJSON);
}
@Test
//@Test
public void unmarshallingJSONTest() throws JAXBException, IOException, SAXException{
System.out.println(DataMinerInvocationTest.class.getMethods()[2].getName()+" called");
System.out.println("unmarshallingJSONTest 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()));
System.out.println("To String is: \n"+IOUtils.toString(dmInvocationJSONFile));
// dmInvocationJSONFile = new FileInputStream(new File("./src/test/resources/DataMinerInvocation.json"));
// DataMinerInvocation dmInvocation = dmMng.unmarshaling(dmInvocationJSONFile, MediaType.ApplicationJSON, false);
// System.out.println(dmInvocation);
//
// ByteArrayOutputStream outStreamXML = dmMng.marshaling(dmInvocation, MediaType.ApplicationXML, true);
// System.out.println(new String(outStreamXML.toByteArray()));
}
@ -121,4 +129,46 @@ public class DataMinerInvocationTest {
// ByteArrayOutputStream outStreamXML = dmMng.marshaling(dmInvocation, MediaType.ApplicationXML, true);
// System.out.println(new String(outStreamXML.toByteArray()));
// }
public static void main(String[] args) {
try{
System.out.println(JAXBContext.newInstance(DataMinerInvocation.class).getClass());
parameters.put("fileId", "http://publicLinkToFile");
parameters.put("[key2]", "[value2]");
dmMng = DataMinerInvocationManager.getInstance();
System.out.println("unmarshallingJSONTest called");
FileInputStream dmInvocationJSONFile = new FileInputStream(new File("./src/test/resources/DataMinerInvocation.json"));
DataMinerInvocation datatminerInvocation = dmMng.unmarshalingJSON(dmInvocationJSONFile);
System.out.println("To String is: \n"+datatminerInvocation.toString());
// String builder = new GsonBuilder().create().t
//System.out.println(gson.fromJson(json, DataMinerInvocationWrapper.class));
Gson gson = new GsonBuilder().setPrettyPrinting().create();
DataMinerInvocationJSONWrapper wrapper = new DataMinerInvocationJSONWrapper(datatminerInvocation);
System.out.println(gson.toJson(wrapper));
// Gson gson = new Gson();
// JsonElement je = gson.toJsonTree(new DataMinerInvocation());
// JsonObject jo = new JsonObject();
// jo.add("dataminer-invocation", je);
// System.out.println(jo.toString());
// ByteArrayOutputStream outStreamXML = dmMng.marshaling(dmInvocation, MediaType.ApplicationXML, true);
// System.out.println(new String(outStreamXML.toByteArray()));
}catch(Exception e){
e.printStackTrace();
}
}
}

View File

@ -1,18 +1,20 @@
{
"dataminer-invocation" : {
"operator-id" : "[THE_OPERATOR_ID]",
"action" : "RUN",
"parameters" : {
"input" : {
"param" : {
"key" : "[key2]",
"value" : "[value2]"
},
"param" : {
"key" : "fileId",
"value" : "http://publicLinkToFile22222"
}
}
"dataminer-invocation": {
"operator-id": "[THE_OPERATOR_ID]",
"action": "RUN",
"parameters": {
"input": {
"param": [
{
"key": "[key2]",
"value": "[value2]"
},
{
"key": "fileId",
"value": "http://publicLinkToFile"
}
]
}
}
}
}
}