Creating IS model refs #4023
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/private/luca.frosini/information-system-model@128746 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
da27ceb1f2
commit
214562bc75
|
@ -15,53 +15,67 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
|||
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
|
||||
*/
|
||||
public class Entities {
|
||||
|
||||
|
||||
protected static final ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
/**
|
||||
* Write the serialisation of a given resource to a given stream.
|
||||
* Write the serialization of a given resource to a given
|
||||
* {@link OutputStream} .
|
||||
*
|
||||
* @param resource the resource
|
||||
* @param stream the stream in input
|
||||
* @throws IOException
|
||||
* @throws JsonMappingException
|
||||
* @throws JsonGenerationException
|
||||
* @throws IOException
|
||||
* @throws JsonMappingException
|
||||
* @throws JsonGenerationException
|
||||
*/
|
||||
public static <T extends OutputStream> T marshal(Object resource,T stream) throws JsonGenerationException, JsonMappingException, IOException {
|
||||
public static <T extends OutputStream> T marshal(Object resource, T stream)
|
||||
throws JsonGenerationException, JsonMappingException, IOException {
|
||||
mapper.writeValue(stream, resource);
|
||||
return stream;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Write the serialisation of a given resource to a given character stream.
|
||||
* Write the serialization of a given resource to a given {@link Writer} .
|
||||
* @param resource the resource
|
||||
* @param stream the stream in input
|
||||
* @throws IOException
|
||||
* @throws JsonMappingException
|
||||
* @throws JsonGenerationException
|
||||
* @param writer the writer in input
|
||||
* @throws IOException
|
||||
* @throws JsonMappingException
|
||||
* @throws JsonGenerationException
|
||||
*/
|
||||
public static <T extends Writer> T marshal(Object resource,T stream) throws JsonGenerationException, JsonMappingException, IOException {
|
||||
mapper.writeValue(stream, resource);
|
||||
return stream;
|
||||
public static <T extends Writer> T marshal(Object resource, T writer)
|
||||
throws JsonGenerationException, JsonMappingException, IOException {
|
||||
mapper.writeValue(writer, resource);
|
||||
return writer;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static <T> T unmarshal(Class<T> resourceClass, Reader reader) throws JsonParseException, JsonMappingException, IOException {
|
||||
|
||||
/**
|
||||
* Creates a resource of given class from its serialization in a given
|
||||
* {@link Reader}.
|
||||
* @param resourceClass the class of the resource
|
||||
* @param reader the reader
|
||||
* @return the resource
|
||||
* @throws JsonParseException
|
||||
* @throws JsonMappingException
|
||||
* @throws IOException
|
||||
*/
|
||||
public static <T> T unmarshal(Class<T> resourceClass, Reader reader)
|
||||
throws JsonParseException, JsonMappingException, IOException {
|
||||
return mapper.readValue(reader, resourceClass);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a resource of given class from its serialisation in a given {@link InputStream}.
|
||||
* Creates a resource of given class from its serialization in a given
|
||||
* {@link InputStream}.
|
||||
* @param resourceClass the class of the resource
|
||||
* @param stream the stream
|
||||
* @return the resource
|
||||
* @throws IOException
|
||||
* @throws JsonMappingException
|
||||
* @throws JsonParseException
|
||||
* @throws IOException
|
||||
* @throws JsonMappingException
|
||||
* @throws JsonParseException
|
||||
*/
|
||||
public static <T> T unmarshal(Class<T> resourceClass, InputStream stream) throws JsonParseException, JsonMappingException, IOException {
|
||||
public static <T> T unmarshal(Class<T> resourceClass, InputStream stream)
|
||||
throws JsonParseException, JsonMappingException, IOException {
|
||||
return mapper.readValue(stream, resourceClass);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue