Main Content

Magnolia Community Forums: Get help with Magnolia: How to configure custom serialization providers for a custom rest-endpoint


  • d_lobo04
    d_lobo04
    Full name: Denis Lobo
    Posts: 3
    Last post: Dec 15, 2016 4:00:42 PM
    Registered on: Dec 15, 2016
    How to configure custom serialization providers for a custom rest-endpoint
    #1 by d_lobo04 on Dec 15, 2016 2:42:01 PM

    Hi,

    The title pretty much states, what I am looking for.
    I have a rest-endpoint, which requests a resource from a third party service.
    When returning the requested resource in the rest-endpoint, I get a serialization error.
    Thus i have written my custom serializer and registered it in object mapper. (But i havent configured anything in magnolia related to marshalling/serializaton). Apparently this doesnt works. Still the default serializer is used.
    In the documentation, I have read that it is possible to define custom marshallers/serializers, but the documentation doesnt state an example for this nor does it mention what to give for the columns "node name" and "value" in magnolia-ui. Or maybe I havent found it. Can you please provide a example or link, where it is shown, how to configure custom serializers for custom end points.

    Kindly regards,
    denis

  • jsimak
    jsimak
    Full name: Jaroslav Simak
    Posts: 26
    Last post: Jan 11, 2017 9:19:37 AM
    Re: How to configure custom serialization providers for a custom rest-endpoint
    #2 by jsimak on Dec 15, 2016 2:59:50 PM

    Hi,

    you can register your own marshaller (provider) in rest-integration module, look at the additionalProviders node.

    HTH.

  • d_lobo04
    d_lobo04
    Full name: Denis Lobo
    Posts: 3
    Last post: Dec 15, 2016 4:00:42 PM
    Registered on: Dec 15, 2016
    Re: How to configure custom serialization providers for a custom rest-endpoint
    #3 by d_lobo04 on Dec 15, 2016 3:58:31 PM

    Thank you, it actually loads the specified provider.. but it seems, that is still not used by magnolia.
    I provided a providerClass, which looks like the following

    class JacksonConfig implements ContextResolver<ObjectMapper>, EndpointDefinitionProvider {
    ...
    }


    Additionally I tried a similar approach with MessageBodyWriter, but i doubt that is useable for json serialization, but anyway .. it looks like:

    class AttributeMessageBodyWriter implements MessageBodyWriter<Attribute>, EndpointDefinitionProvider {

    }

    Should it be ConfiguredEndpointProvider ?

    I print a debug message within the constructor, but I cant see the message in logs.
    Is there also a example of code, showing how to implement the custom provider within an magnolia module

  • d_lobo04
    d_lobo04
    Full name: Denis Lobo
    Posts: 3
    Last post: Dec 15, 2016 4:00:42 PM
    Registered on: Dec 15, 2016
    Re: How to configure custom serialization providers for a custom rest-endpoint
    #4 by d_lobo04 on Dec 15, 2016 4:00:42 PM

    Also the stacktrace (of serialization error) doesnt show up my serializer:

    at org.codehaus.jackson.map.JsonMappingException.wrapWithPath(JsonMappingException.java:218)
    at org.codehaus.jackson.map.JsonMappingException.wrapWithPath(JsonMappingException.java:183)
    at org.codehaus.jackson.map.ser.std.SerializerBase.wrapAndThrow(SerializerBase.java:140)
    at org.codehaus.jackson.map.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:158)
    at org.codehaus.jackson.map.ser.BeanSerializer.serialize(BeanSerializer.java:112)
    at org.codehaus.jackson.map.ser.std.StdContainerSerializers$IndexedListSerializer.serializeContents(StdContainerSerializers.java:122)
    at org.codehaus.jackson.map.ser.std.StdContainerSerializers$IndexedListSerializer.serializeContents(StdContainerSerializers.java:71)
    at org.codehaus.jackson.map.ser.std.AsArraySerializerBase.serialize(AsArraySerializerBase.java:86)
    at org.codehaus.jackson.map.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:446)
    at org.codehaus.jackson.map.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:150)
    at org.codehaus.jackson.map.ser.BeanSerializer.serialize(BeanSerializer.java:112)
    at org.codehaus.jackson.map.ser.StdSerializerProvider._serializeValue(StdSerializerProvider.java:610)
    at org.codehaus.jackson.map.ser.StdSerializerProvider.serializeValue(StdSerializerProvider.java:256)
    at org.codehaus.jackson.map.ObjectMapper.writeValue(ObjectMapper.java:1613)
    at org.codehaus.jackson.jaxrs.JacksonJsonProvider.writeTo(JacksonJsonProvider.java:559)
    at org.jboss.resteasy.core.interception.AbstractWriterInterceptorContext.writeTo(AbstractWriterInterceptorContext.java:129)
    at org.jboss.resteasy.core.interception.ServerWriterInterceptorContext.writeTo(ServerWriterInterceptorContext.java:62)
    at org.jboss.resteasy.core.interception.AbstractWriterInterceptorContext.proceed(AbstractWriterInterceptorContext.java:118)
    at org.jboss.resteasy.plugins.interceptors.encoding.GZIPEncodingInterceptor.aroundWriteTo(GZIPEncodingInterceptor.java:100)
    at org.jboss.resteasy.core.interception.AbstractWriterInterceptorContext.proceed(AbstractWriterInterceptorContext.java:122)
    at org.jboss.resteasy.core.ServerResponseWriter.writeNomapResponse(ServerResponseWriter.java:99)
    at org.jboss.resteasy.core.SynchronousDispatcher.writeResponse(SynchronousDispatcher.java:411)
    at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:376)
    at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:179)
    at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:220)
    at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:56)
    at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:51)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    at info.magnolia.cms.filters.ServletDispatchingFilter.doFilter(ServletDispatchingFilter.java:148)
    at info.magnolia.cms.filters.AbstractMgnlFilter.doFilter(AbstractMgnlFilter.java:85)
    at info.magnolia.cms.filters.MgnlFilterChain.doFilter(MgnlFilterChain.java:79)
    at info.magnolia.cms.filters.MgnlFilterChain.doFilter(MgnlFilterChain.java:81)
    at info.magnolia.cms.filters.CompositeFilter.doFilter(CompositeFilter.java:65)
    at info.magnolia.cms.filters.AbstractMgnlFilter.doFilter(AbstractMgnlFilter.java:85)
    at info.magnolia.cms.filters.MgnlFilterChain.doFilter(MgnlFilterChain.java:79)
    at info.magnolia.cms.filters.VirtualUriFilter.doFilter(VirtualUriFilter.java:69)
    at info.magnolia.cms.filters.AbstractMgnlFilter.doFilter(AbstractMgnlFilter.java:85)
    at info.magnolia.cms.filters.MgnlFilterChain.doFilter(MgnlFilterChain.java:79)
    at info.magnolia.module.cache.executor.Bypass.processCacheRequest(Bypass.java:58)
    at info.magnolia.module.cache.executor.CompositeExecutor.processCacheRequest(CompositeExecutor.java:67)
    at info.magnolia.module.cache.filter.CacheFilter.doFilter(CacheFilter.java:174)
    at info.magnolia.cms.filters.OncePerRequestAbstractMgnlFilter.doFilter(OncePerRequestAbstractMgnlFilter.java:59)
    at info.magnolia.cms.filters.MgnlFilterChain.doFilter(MgnlFilterChain.java:79)
    ....

You don't have the permission to post on this thread

Sign in

To login on this forum, you can use your Magnolia Forge, Support or Partner account, or, below, your Google, Yahoo! or OpenID account. If you have trouble logging in, or any other sort of issue, please let us know in the Meta forum, on the user-list, or simply by email at forum-admin at magnolia-cms dot com.

* Required

... or sign in with:

  • icon http://{your-openid-url}
  • icon
  • icon https://me.yahoo.com/