users@jersey.java.net

[Jersey] Jersey 2.0 How to provide custom serialization/de-serialization via moxy

From: Piers Powlesland <piers_at_aptusinteractive.com>
Date: Mon, 14 Oct 2013 17:19:56 +0100

Hi I'm trying to send from server to client a simple object holding a list
of java.nio.file.Path objects.

Using the following moxy configuration results in an empty list being
serialized out.


...

register(createMoxyJsonResolver());
...
public static ContextResolver<MoxyJsonConfig> createMoxyJsonResolver() {
        final MoxyJsonConfig moxyJsonConfig = new MoxyJsonConfig();
        Map<String, String> namespacePrefixMapper = new HashMap<String,
String>(1);
        namespacePrefixMapper.put("http://www.w3.org/2001/XMLSchema-instance",
"xsi");

moxyJsonConfig.setNamespacePrefixMapper(namespacePrefixMapper).setNamespaceSeparator(':');
        return moxyJsonConfig.resolver();
    }

...

I guess that i need to tell moxy how to serialize and deserialize Path
objects but looking at the examples I can't see any way to do this since I
cannot add annotations to Path. So does anyone know how to provide a custom
serializer/de-serializer for an object that cannot be annotated?

Thanks

Piers