AndroidMapperObject

Additional

Language
Java
Version
v0.1.2 (Nov 8, 2016)
Created
Oct 12, 2016
Updated
Nov 8, 2016 (Retired)
Owner
Gabriel Perez (Gperez88)
Contributor
Gabriel Perez (Gperez88)
1
Activity
Badge
Generate
Download
Source code

AndroidMapperObject

AndroidMapperObject is an extension the library MapperObject which it is a library that allows you to transfer data between two objects.

It support's :

  • Object to Object data transfer
  • Collection to Collection data transfer
  • Break circular reference

Usage

Add the dependencies to your gradle file:

dependencies {
      compile 'com.github.gperez88:androidMapperObject:0.1.2'
}

It have two main annotations :

At the class level

@EntityMapper

At the fields level

the mapping annotation

@Mapping(name = "roles", otherType = true)
//name is is the field name on the other class
// otherType tells the mapper engine that this field has another mappins inside it.

the break circular reference annotation

@BackReference

if you need to transfer the data in this class to another one

public class UserEntity {
    private int id;
    private String username;
    private String password;
    //getters and setters
}

Extend the ParseableObject class like so :

@EntityMapper
public class UserDTO extends ParsableObject<UserEntity,UserDTO>{
    @Mapping
    private int id;
    @Mapping
    private String username;
    @Mapping
    private String password;
    
    public UserDTO(){}
    
    //load the entity object
    public UserDTO(UserEntity userEntity){
      load(userEntity);
    }
    
    //getters and setters
}

Object to Object data transfer

transfer data the Entity to DTO

UserDTO mapperObjectUserDTO = new UserDTO(userEntity);

also you can use the instance of MapperObject

Mapper mapperObject = MapperObject.getInstance();
UserDTO mapperObjectUserDTO = mapperObject.map(userEntity, UserDTO.class);

transfer data the DTO to Entity

userEntity = mapperObjectUserDTO.parse();

Collection to Collection data transfer

transfer data the Entity to DTO

Mapper mapperObject = MapperObject.getInstance();
List<UserDTO> usersDTO = mapperObject.map(userEntities, UserDTO.class);

transfer data the DTO to Entity

userEntities = new UserDTO().convertDomainList(usersDTO);

License

Copyright 2016 Gabriel Perez.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

Apache License, Version 2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.