Skip to content
This repository has been archived by the owner on Feb 18, 2023. It is now read-only.
/ object-projection Public archive

Declarative Data Transfer Objects Composition and Extraction

License

Notifications You must be signed in to change notification settings

filip26/object-projection

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Java CI with Maven Language grade: Java codecov License

Object Projection

Projection
      .bind(EmployeeTo.class)

      .map("name")    // DOE, John   - alt .map(EmployeeTo::getName, EmployeeTo::setName)
            .sources()
                .conversion(String[].class, String.class)
                    .forward(sources -> sources[1] + ", " + sources[0])    // DOE, John
                    
                .source(Person.class, "firstName")                // John
                    
                .source(Person.class, "lastName")                 // Doe
                    .conversion(String.class, String.class)
                        .forward(String::toUpperCase)             // DOE
          
      .map("employer")
            .source(Employer.class, "name")
            .optional()
                
      .build();
@Projection
public class RecordTo {

  @Sources(
      value = {
              @Source(type=User.class, property = "username"),
              @Source(type=Repository.class, property = "id"),
              },
      map = @Conversion(
              type = URITemplate.class,
              value = "https://www.example.org/{username}/{repositoryId}"
              )
      )
  String href;  // e.g. https://www.example.org/filip26/R1234

  ...
}

Projection.scan(RecordTo.class).build();
  @Source(value = "prices"
      map = {
        @Conversion(type = Flat.class),
        @Conversion(type = Sum.class)
        }
      )
  Long total;
  ...
  @Provided(optional = true)
  String context;
  ...
}
  @Sources(value = {
      @Source("stringProperty"),
      @Source("integerProperty"),
      @Source("booleanProperty"),
      })
  Collection<String> list;
  ...
}
Projection
    .hashMap()

        .mapString("code")
            .source(Item.class)
          
        .mapDouble("price");
            .source(Item.class, "totalPrice")
          
        .mapReference("details", ItemDetailsTo.class)
             .provided()
                          
        .build();