Package org.nuxeo.ecm.core.io.registry
Class MarshallerHelper
java.lang.Object
org.nuxeo.ecm.core.io.registry.MarshallerHelper
Quick use of
MarshallerRegistry.- Since:
- 7.2
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> List<T> jsonToList(Class<T> elementType, String json, RenderingContext ctx) static <T> TjsonToObject(Class<T> type, Type genericType, String json, RenderingContext ctx) static <T> TjsonToObject(Class<T> type, String json, RenderingContext ctx) static <T> StringlistToJson(Class<T> elementType, List<T> list, RenderingContext ctx) Convert the given list to json.static <T> StringobjectToJson(Type genericType, T object, RenderingContext ctx) Convert the given object to json.static <T> StringobjectToJson(T object, RenderingContext ctx) Convert the given object to json.
-
Method Details
-
objectToJson
Convert the given object to json.- Parameters:
object- The object to convert as json.ctx- May be null - otherwise, useRenderingContext.CtxBuilderto 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.CtxBuilderto 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.CtxBuilderto create the context.- Returns:
- the resulting json.
- 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
-
jsonToObject
public static <T> T jsonToObject(Class<T> type, Type genericType, String json, RenderingContext ctx) throws IOException - Throws:
IOException- Since:
- 10.2
-
jsonToList
public static <T> List<T> jsonToList(Class<T> elementType, String json, RenderingContext ctx) throws IOException - Throws:
IOException- Since:
- 10.2
-