Introducing ShapeShift: A lightweight, modular, performant and extensible object mapping library for Kotlin/Java
Tags: java, kotlin, opensource, architecture
Published: 2022-10-12 12:07:23

# WHY

## The short answer
We needed a simple to use, minimal boiler plate mapping engine, that is also flexible and supports the most advanced use cases.

## The long answer
A few years ago we got tired of developing the same boiler plate code for CRUD and decided to develop a generic CRUD framework.

As a part of this framework we needed an object mapping library and could not find one that answered all of our requirements.

The first iteration of the library was part of the entire CRUD framework. However, some time ago we decided we want to start contributing to the open source community and we thought "What is the best way to contribute if not to release our CRUD framework?". The issue with this thought is that the framework is huge and contains lots of code, polishing it and getting it ready to be published as open source would take a lot of time (documentation anyone?).

Our solution was to separate the framework into multiple smaller libraries we can polish and publish in smaller time frames. The first of these libraries is [ShapeShift](https://shapeshift.krud.dev/).

# WHAT

## The short answer
ShapeShift will help you transform object of type A to object of type B easily, fast and without boiler plate code.

ShapeShift main features:
- Auto mapping
- Custom field transformers
- Default transformers
- Deep mapping
- Multiple mapping targets
- Conditional mapping
- Mapping decorators
- Seamless spring integration
- Native Kotlin DSL API
- Java builder API
- Annotations API
- Native Android support

## The longer answer
ShapeShift's job seems simple, convert object of type A to object of type B. But to do its job in the best way possible, the library offers lots of features, to name a few: 
- [Advanced auto mapping](https://shapeshift.krud.dev/features/auto-mapping) - Automatically map fields with the same name from the source object to the target object. Control wether to map only fields of the same type or use the advanced [default transformers](https://shapeshift.krud.dev/features/transformers#default-transformers) feature to auto map fields of different types!
- [Seamless Spring integration](https://shapeshift.krud.dev/guides/spring-usage) - ShapeShift's Spring Boot library allows to integrate it with Spring easily. Use Spring's power to create custom transformers beans with access to DB or other resources.

More about the advanced features with code examples is available in [Kotlin version](https://dev.to/krud/object-mapping-advanced-features-qol-with-kotlin-5dgn) and [Java version](https://dev.to/krud/object-mapping-advanced-features-qol-with-java-43m9).

# HOW

## The short answer
ShapeShift supports multiple APIs to configure your mappings.
[Annotations](https://shapeshift.krud.dev/api-documentation/annotations), [Kotlin DSL](https://shapeshift.krud.dev/api-documentation/dsl) and [Java Builder](https://shapeshift.krud.dev/api-documentation/java-builder).

## The long answer
ShapeShift's documentation is available [here](https://shapeshift.krud.dev/). You can check our [Quick Start](https://shapeshift.krud.dev/introduction/quick-start) guide to get it up and running in 5 minutes.

Built with **Kotlin** in mind, ShapeShift was designed around its ecosystem and best practices. The library APIs for mapping with Kotlin:

- [Annotations](https://shapeshift.krud.dev/api-documentation/annotations) - Fully featured annotation based mapping, just add annotations to your objects and ShapeShift handles the rest. Including using custom field transformers, conditional mapping, advanced object decoration and much more.
- [Kotlin DSL](https://shapeshift.krud.dev/api-documentation/dsl) - Allowing you to define the relations between objects. This allows you to map objects you can't change (or don't want to), like objects from 3rd party libraries. Additionally you can define inline transformations, conditions and decorations, enabling deep customization and very advanced mapping.

ShapeShift also has full **Java** support available with multiple APIs for mapping:

- [Annotations](https://shapeshift.krud.dev/api-documentation/annotations) - Same API as Kotlin with full Java support.
- [Java Builder](https://shapeshift.krud.dev/api-documentation/java-builder) - The equivalent Java API for the Kotlin DSL. Allowing you to define the relations between objects without modifying their code, and map objects you can't change (or don't want to).

# Final words
We poured our love, time, knowledge and what not into ShapeShift. I'm proud of the result and our greatest achievement is to be able to help others with their work.

If you would like to contribute, please feel free to open issues, join as a contributor or star the [repository](https://github.com/krud-dev/shapeshift/). Thanks in advance!