Search code examples
c#restserializationnancy

NancyFx per module or per route serialization


I use NancyFx, I've tried to find the answer prior to question.

I have a single return type per module, but in different URL routes I need to serialize it differently, just specific properties. If I wire serialization in Nancy pipeline, it touches all routes.

Is it possible to customize serialization per route or module without copy pasting the same type in different namespaces?


Solution

  • I've come up with 2 solutions:

    1. Derived type with JsonConvert attribute on corresponding overriden props;
    2. Using serialization within module and return a string.