Mappyfy
Mapping library for java that recursively copies data from one object to another.
Install / Use
/learn @erafaelmanuel/MappyfyREADME
Overview
A Reflection-based mappers library that maps objects to another objects. It can be very useful when developing multi-layered applications.
- Map complex and deeply structured objects
- Create converters for complete control over the mapping of a specific set of objects anywhere in the object graph
- Easy-to-use
Download
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependency>
<groupId>com.github.erafaelmanuel</groupId>
<artifactId>mappyfy</artifactId>
<version>1.0.5</version>
</dependency>
How to use
Suppose we have some instances of class Person that we’d like to map to instances of another class PersonDto.
public class Person {
String name;
int age;
}
public class PersonDto {
String fullname;
int age;
}
final Mapper mapper = new Mapper();
Person person = new Person("Foo", 3);
PersonDto dto = mapper.from(person).bind("name", "fullname").toInstanceOf(PersonDto.class);
TypeConverter
In order to create your own custom converter you need to extends the TypeConverter and add the two generic type.
public class MyCustomTypeConverter extends TypeConverter<Integer, Date> {
@Override
public Date convertTo(Long o) {
// implementation
}
@Override
public Long convertFrom(Date o) {
// implementation
}
}
Use converters where the mapper can't handle mapping an instance of a source object into a specific destination type. Example:
public class Bar {
String name;
Date date;
}
public class Foo {
String name;
String date;
}
final Mapper mapper = new Mapper();
Bar bar = new Bar("I love PHP!", new Date());
Foo foo = mapper
.from(bar)
.parseFieldWith("date", new MyCustomTypeConverter())
.toInstanceOf(Foo.class);
Related Skills
node-connect
342.0kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
84.7kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
342.0kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
commit-push-pr
84.7kCommit, push, and open a PR
