Entity-Property mapping

Vikhyath Shetty 25 Reputation points
2023-03-02T09:06:48.0266667+00:00

How do we map the entities/properties from a JSON to another JSON with a different format/structure? The input JSON is complex and has multiple levels and array elements. This needs to be deserialized and mapped to another Entity.

I am planning to use the DB to store mapping configurations, ex: source property "id" maps to destination property "Identifier" etc

I have been trying to use strongly typed C# model classes to deserialize and map to the destination model, however I am aware that this is not a very extensible solution and any changes in the source/destination JSON payload would require code and DB changes.

Is there any solution that is configurable and dynamic, that can solve this problem?

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,366 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Alan Farias 745 Reputation points
    2023-03-02T13:37:02.5766667+00:00

    One solution to map entities/properties from one JSON to another with a different structure is to use a tool or library that supports mapping, such as AutoMapper. AutoMapper is a widely used open-source library for .NET that enables object-object mapping. You can define mapping configurations in code, such as property names, and use them to map between different object types. It supports complex object graphs and collections, and also supports custom mapping logic.

    Another approach is to use a configuration-based mapping tool like FRENDS Mapper. FRENDS Mapper is an integration platform that provides a visual editor for creating and managing data mappings between different formats, such as JSON, XML, CSV, and SQL. With FRENDS Mapper, you can define mapping rules and transformations using a graphical user interface, and store them in a configuration file. This approach allows you to easily modify mappings without changing code or making database changes.

    Regarding the use of the database to store mapping configurations, this is a good approach as it allows you to separate the mapping logic from the application code and provides a more flexible solution. You can define the mapping rules and configurations in a database table and retrieve them at runtime, then use them to dynamically map the objects. This approach allows you to modify the mapping configurations without redeploying the application. However, it requires careful design and management of the database table to ensure scalability, maintainability, and security.

    In summary, there are several tools and approaches that you can use to map entities/properties from one JSON to another with a different structure. AutoMapper and FRENDS Mapper are two examples of tools that you can use, while storing mapping configurations in a database is a good practice that can improve flexibility and maintainability.