Package org.nuxeo.ecm.core.io.registry
Class MarshallerHelper
- java.lang.Object
-
- org.nuxeo.ecm.core.io.registry.MarshallerHelper
-
public final class MarshallerHelper extends Object
Quick use ofMarshallerRegistry
.- Since:
- 7.2
-
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static <T> List<T>
jsonToList(Class<T> elementType, String json, RenderingContext ctx)
static <T> T
jsonToObject(Class<T> type, Type genericType, String json, RenderingContext ctx)
static <T> T
jsonToObject(Class<T> type, String json, RenderingContext ctx)
static <T> List<T>
listToJson(Class<T> elementType, String json, RenderingContext ctx)
Deprecated.since 10.2, usejsonToList(Class, String, RenderingContext)
instead.static <T> String
listToJson(Class<T> elementType, List<T> list, RenderingContext ctx)
Convert the given list to json.static <T> T
objectToJson(Class<T> type, Type genericType, String json, RenderingContext ctx)
Deprecated.since 10.2, usejsonToObject(Class, Type, String, RenderingContext)
instead.static <T> T
objectToJson(Class<T> type, String json, RenderingContext ctx)
Deprecated.since 10.2 usejsonToObject(Class, String, RenderingContext)
instead.static <T> String
objectToJson(Type genericType, T object, RenderingContext ctx)
Convert the given object to json.static <T> String
objectToJson(T object, RenderingContext ctx)
Convert the given object to json.
-
-
-
Method Detail
-
objectToJson
public static <T> String objectToJson(T object, RenderingContext ctx) throws IOException
Convert the given object to json.- Parameters:
object
- The object to convert as json.ctx
- May be null - otherwise, useRenderingContext.CtxBuilder
to create the context.- Returns:
- the resulting json.
- Throws:
IOException
- Since:
- 7.2
-
objectToJson
public static <T> String objectToJson(Type genericType, T object, RenderingContext ctx) throws IOException
Convert the given object to json.Specify its generic type to be sure to get the best marshaller to manage it.
- Parameters:
genericType
- The generic type of the object. You can easily create parametrize type usingTypeUtils.parameterize(Class, Type...)
object
- The object to convert as json.ctx
- May be null - otherwise, useRenderingContext.CtxBuilder
to create the context.- Returns:
- the resulting json.
- Throws:
IOException
- Since:
- 7.2
-
listToJson
public static <T> String listToJson(Class<T> elementType, List<T> list, RenderingContext ctx) throws IOException
Convert the given list to json.Specify the list element type to get the best marshaller to manage conversion.
- Parameters:
elementType
- The element type of the list.list
- The list to convert.ctx
- May be null - otherwise, useRenderingContext.CtxBuilder
to create the context.- Returns:
- the resulting json.
- Throws:
IOException
- Since:
- 7.2
-
objectToJson
@Deprecated public static <T> T objectToJson(Class<T> type, String json, RenderingContext ctx) throws IOException
Deprecated.since 10.2 usejsonToObject(Class, String, RenderingContext)
instead.Read an object of the given type from given json.- Parameters:
type
- The type of the read object.json
- The json to parse.ctx
- May be null - otherwise, useRenderingContext.CtxBuilder
to create the context.- Returns:
- the resulting object.
- Throws:
IOException
- Since:
- 7.2
-
jsonToObject
public static <T> T jsonToObject(Class<T> type, String json, RenderingContext ctx) throws IOException
- Throws:
IOException
- Since:
- 10.2
-
objectToJson
@Deprecated public static <T> T objectToJson(Class<T> type, Type genericType, String json, RenderingContext ctx) throws IOException
Deprecated.since 10.2, usejsonToObject(Class, Type, String, RenderingContext)
instead.Read an object of the given type from given json.Specify its generic type to be sure to get the best marshaller to manage it.
- Parameters:
type
- The type of the read object.genericType
- The generic type of the object. You can easily create parametrize type usingTypeUtils.parameterize(Class, Type...)
json
- The json to parse.ctx
- May be null - otherwise, useRenderingContext.CtxBuilder
to create the context.- Returns:
- the resulting object.
- Throws:
IOException
- Since:
- 7.2
-
jsonToObject
public static <T> T jsonToObject(Class<T> type, Type genericType, String json, RenderingContext ctx) throws IOException
- Throws:
IOException
- Since:
- 10.2
-
listToJson
@Deprecated public static <T> List<T> listToJson(Class<T> elementType, String json, RenderingContext ctx) throws IOException
Deprecated.since 10.2, usejsonToList(Class, String, RenderingContext)
instead.Read an object of the given type from given json.Specify the list element type to get the best marshaller to manage conversion.
- Parameters:
elementType
- The element type of the list.json
- The json to parse.ctx
- May be null - otherwise, useRenderingContext.CtxBuilder
to create the context.- Returns:
- the resulting list.
- Throws:
IOException
- Since:
- 7.2
-
jsonToList
public static <T> List<T> jsonToList(Class<T> elementType, String json, RenderingContext ctx) throws IOException
- Throws:
IOException
- Since:
- 10.2
-
-