Skip to content
This repository was archived by the owner on Jun 11, 2023. It is now read-only.

devindi/mapper-generator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

060d017 · Sep 11, 2019

History

27 Commits
Sep 11, 2019
Sep 11, 2019
Sep 11, 2019
Sep 11, 2019
Sep 11, 2019
Sep 11, 2019
Aug 27, 2017
Sep 16, 2017
Aug 30, 2017
Aug 28, 2017
Aug 28, 2017
Aug 30, 2017
Aug 28, 2017

Repository files navigation

mapper-generator

An annotation processor for generating bean mappers

IDE support

This annotation processor is supported by Android Studio out-of-box.
You have to set-up processor and generated code usage in your IntelliJ IDEA project.

Usage

This processor generates mapper from getters to constructor args.

//gradle deps (don't forget to apply 'net.ltgt.apt' or other annotation plugin):
dependencies {
    compile 'com.devindi.mapper:library:0.1'
    apt 'com.devindi.mapper:processor:0.1.1'
}

//Source:   
public class PersonDto {

    private String name;
    private int age;

    //constructor, setters or other methods

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}

//Target:
public class Person {

    private final String name;
    private final int age;

    public Person(int age, String name) {
        this.name = name;
        this.age = age;
    }
}

//Mapper definition:
@Mapper
public interface PersonMapper {
    Person toModel(PersonDto dto);
}

//Generated code:
public class PersonMapperImpl implements PersonMapper {
  @Override
  public Person toModel(PersonDto dto) {
    return new com.example.Person(dto.getAge(),dto.getName());
  }
}

Development

Debugging

IDE setup

Create 'Remote' debug configuration for target module ('sample' for this project)

debug run

Build target with debug flag
./gradlew --no-daemon -Dorg.gradle.debug=true :sample:clean :sample:build
Run 'Remote' configuration that you created before.

ToDo list

  • Type converters (String <-> Long, Double <-> Float, custom converters)
  • Collection mapping (List<Source> -> List<Target>)
  • Recursive mapping
  • NULL values
  • Default values
  • Primitives

Packages

No packages published

Languages