项目作者: devindi

项目描述 :
An annotation processor for generating bean mappers
高级语言: Java
项目地址: git://github.com/devindi/mapper-generator.git
创建时间: 2017-08-27T21:02:06Z
项目社区:https://github.com/devindi/mapper-generator

开源协议:MIT License

下载


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.

  1. //gradle deps (don't forget to apply 'net.ltgt.apt' or other annotation plugin):
  2. dependencies {
  3. compile 'com.devindi.mapper:library:0.1'
  4. apt 'com.devindi.mapper:processor:0.1.1'
  5. }
  6. //Source:
  7. public class PersonDto {
  8. private String name;
  9. private int age;
  10. //constructor, setters or other methods
  11. public String getName() {
  12. return name;
  13. }
  14. public void setName(String name) {
  15. this.name = name;
  16. }
  17. }
  18. //Target:
  19. public class Person {
  20. private final String name;
  21. private final int age;
  22. public Person(int age, String name) {
  23. this.name = name;
  24. this.age = age;
  25. }
  26. }
  27. //Mapper definition:
  28. @Mapper
  29. public interface PersonMapper {
  30. Person toModel(PersonDto dto);
  31. }
  32. //Generated code:
  33. public class PersonMapperImpl implements PersonMapper {
  34. @Override
  35. public Person toModel(PersonDto dto) {
  36. return new com.example.Person(dto.getAge(),dto.getName());
  37. }
  38. }

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\ -> List\)
  • Recursive mapping
  • NULL values
  • Default values
  • Primitives