Introducing ShapeShift: A lightweight, modular, performant and extensible object mapping library for Kotlin/Java

Introducing ShapeShift: A lightweight, modular, performant and extensible object mapping library for Kotlin/Java


3 min read


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.


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 - 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 feature to auto map fields of different types!
  • Seamless Spring integration - 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 and Java version.


The short answer

ShapeShift supports multiple APIs to configure your mappings. Annotations, Kotlin DSL and Java Builder.

The long answer

ShapeShift's documentation is available here. You can check our 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 - 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 - 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 - Same API as Kotlin with full Java support.
  • 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. Thanks in advance!