Class ExceptionMapper
- java.lang.Object
-
- org.gcube.informationsystem.resourceregistry.api.exceptions.ExceptionMapper
-
public abstract class ExceptionMapper extends Object
Jackson-based (de)serializer for theResourceRegistryExceptionhierarchy, shared by client and server so that a concrete exception subclass thrown server-side is restored as that same concrete type client-side after crossing the wire, relying on the@JsonTypeInfo/subtype registration declared onResourceRegistryException.Not to be confused with
javax.ws.rs.ext.ExceptionMapper, the unrelated JAX-RS interface implemented server-side (asResourceRegistryExceptionMapper) to turn a thrown exception into an HTTP response.- Author:
- Luca Frosini (ISTI - CNR)
-
-
Field Summary
Fields Modifier and Type Field Description protected static org.gcube.com.fasterxml.jackson.databind.ObjectMappermapperThe mapper.
-
Constructor Summary
Constructors Constructor Description ExceptionMapper()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static org.gcube.com.fasterxml.jackson.databind.ObjectMappergetObjectMapper()Gets the object mapper.static <RRE extends ResourceRegistryException>
Stringmarshal(RRE object)Returns the String serialization of a given resource.static <T extends OutputStream,RRE extends ResourceRegistryException>
Tmarshal(RRE object, T stream)Writes the serialization of a given resource to a givenOutputStream.static <RRE extends ResourceRegistryException>
RREunmarshal(Class<RRE> clz, InputStream stream)Creates a resource of given class from its serialization in a givenInputStream.static <RRE extends ResourceRegistryException>
RREunmarshal(Class<RRE> clz, Reader reader)Creates a resource of given class from its serialization in a givenReader.static <RRE extends ResourceRegistryException>
RREunmarshal(Class<RRE> clz, String string)Creates a resource of given class from its serialization in a given String.
-
-
-
Method Detail
-
getObjectMapper
public static org.gcube.com.fasterxml.jackson.databind.ObjectMapper getObjectMapper()
Gets the object mapper.- Returns:
- the ObjectMapper
-
marshal
public static <T extends OutputStream,RRE extends ResourceRegistryException> T marshal(RRE object, T stream) throws org.gcube.com.fasterxml.jackson.core.JsonGenerationException, org.gcube.com.fasterxml.jackson.databind.JsonMappingException, IOException
Writes the serialization of a given resource to a givenOutputStream.- Type Parameters:
T- the generic typeRRE- the generic type- Parameters:
object- the resourcestream- the stream in input- Returns:
- the given stream
- Throws:
IOException- Signals that an I/O exception has occurred.org.gcube.com.fasterxml.jackson.databind.JsonMappingException- the json mapping exceptionorg.gcube.com.fasterxml.jackson.core.JsonGenerationException- the json generation exception
-
marshal
public static <T extends Writer,RRE extends ResourceRegistryException> T marshal(RRE object, T writer) throws org.gcube.com.fasterxml.jackson.core.JsonGenerationException, org.gcube.com.fasterxml.jackson.databind.JsonMappingException, IOException
Writes the serialization of a given resource to a givenWriter.- Type Parameters:
T- the generic typeRRE- the generic type- Parameters:
object- the resourcewriter- the writer in input- Returns:
- the given writer
- Throws:
IOException- Signals that an I/O exception has occurred.org.gcube.com.fasterxml.jackson.databind.JsonMappingException- the json mapping exceptionorg.gcube.com.fasterxml.jackson.core.JsonGenerationException- the json generation exception
-
marshal
public static <RRE extends ResourceRegistryException> String marshal(RRE object) throws org.gcube.com.fasterxml.jackson.core.JsonProcessingException
Returns the String serialization of a given resource.- Type Parameters:
RRE- the generic type- Parameters:
object- the resource- Returns:
- the String serialization of a given resource
- Throws:
org.gcube.com.fasterxml.jackson.core.JsonProcessingException- the json processing exception
-
unmarshal
public static <RRE extends ResourceRegistryException> RRE unmarshal(Class<RRE> clz, Reader reader) throws org.gcube.com.fasterxml.jackson.core.JsonParseException, org.gcube.com.fasterxml.jackson.databind.JsonMappingException, IOException
Creates a resource of given class from its serialization in a givenReader.- Type Parameters:
RRE- the generic type- Parameters:
clz- the class of the resourcereader- the reader- Returns:
- the resource
- Throws:
org.gcube.com.fasterxml.jackson.core.JsonParseException- the json parse exceptionorg.gcube.com.fasterxml.jackson.databind.JsonMappingException- the json mapping exceptionIOException- Signals that an I/O exception has occurred.
-
unmarshal
public static <RRE extends ResourceRegistryException> RRE unmarshal(Class<RRE> clz, InputStream stream) throws org.gcube.com.fasterxml.jackson.core.JsonParseException, org.gcube.com.fasterxml.jackson.databind.JsonMappingException, IOException
Creates a resource of given class from its serialization in a givenInputStream.- Type Parameters:
RRE- the generic type- Parameters:
clz- the class of the resourcestream- the stream- Returns:
- the resource
- Throws:
IOException- Signals that an I/O exception has occurred.org.gcube.com.fasterxml.jackson.databind.JsonMappingException- the json mapping exceptionorg.gcube.com.fasterxml.jackson.core.JsonParseException- the json parse exception
-
unmarshal
public static <RRE extends ResourceRegistryException> RRE unmarshal(Class<RRE> clz, String string) throws org.gcube.com.fasterxml.jackson.core.JsonParseException, org.gcube.com.fasterxml.jackson.databind.JsonMappingException, IOException
Creates a resource of given class from its serialization in a given String.- Type Parameters:
RRE- the generic type- Parameters:
clz- the class of the resourcestring- the string- Returns:
- the resource
- Throws:
org.gcube.com.fasterxml.jackson.core.JsonParseException- the json parse exceptionorg.gcube.com.fasterxml.jackson.databind.JsonMappingException- the json mapping exceptionIOException- Signals that an I/O exception has occurred.
-
-