0

I want to define a contract for a DTO which a consuming API project will implement and return as JSON.

From my perspective there are three concerns here:

  1. The properties defined by the contract
  2. The implementation (for example, this might be an Entity Framework POCO)
  3. The serialization metadata which defines the returned JSON

I'd like to define these three parts separately, but to the best of my knowledge I have to add the serialization decoration (DataMember attributes etc) in the implemtation of my contract. Which means the implementation is coupled with the JSON representation.

Is it possible to separate this serialization metadata into a separate class?

4

1 Answer 1

2

I always find creating separate models for each purpose is beneficial then use AutoMapper to map between these model.

You could also create conventions instead but this can sometimes feel like magic.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.