Added method to marshal list

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-publishing/document-store-lib@150549 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Luca Frosini 2017-06-26 15:47:52 +00:00
parent 51720268b2
commit 8bed93f60a
1 changed files with 9 additions and 7 deletions

View File

@ -4,6 +4,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Reader;
import java.io.StringWriter;
import java.io.Writer;
import java.util.ArrayList;
import java.util.List;
@ -35,7 +36,6 @@ public class DSMapper {
}
static {
mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
mapper.registerModule(new IdentifiableDeserializableModule());
@ -87,16 +87,18 @@ public class DSMapper {
/**
* Return the String serialization of a given resource
* @param object the resource
* @param list the list of Records
* @return the String serialization of a given resource
* @throws JsonProcessingException
* @throws IOException
*/
public static <R extends Record> String marshalR(R[] object) throws JsonProcessingException {
return mapper.writeValueAsString(object);
public static <R extends Record> String marshal(List<R> list) throws IOException {
final StringWriter sw =new StringWriter();
mapper.writeValue(sw, list);
String ret = sw.toString();
sw.close();
return ret;
}
/**
* Creates a resource of given class from its serialization in a given
* {@link Reader}.