-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #99 from fujaba/feat/dto-annotation
DTO Mapping
- Loading branch information
Showing
16 changed files
with
1,146 additions
and
31 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package org.fulib.builder.reflect; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
/** | ||
* Allows creating Data Transfer Object (DTO) classes by copying attributes from a model class. | ||
* Associations are automatically converted to String attributes meant for holding the ID of the link target. | ||
* | ||
* @since 1.6 | ||
*/ | ||
@Target(ElementType.TYPE) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface DTO | ||
{ | ||
/** | ||
* @return the model class to copy attributes from | ||
*/ | ||
Class<?> model(); | ||
|
||
/** | ||
* @return the names of fields that should be included. Ignored if empty. | ||
*/ | ||
String[] pick() default {}; | ||
|
||
/** | ||
* @return the names of fields that should be excluded | ||
*/ | ||
String[] omit() default {}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package org.fulib.docs.dtos.dto; | ||
|
||
import org.fulib.builder.ClassModelDecorator; | ||
import org.fulib.builder.ClassModelManager; | ||
import org.fulib.builder.Type; | ||
import org.fulib.builder.reflect.DTO; | ||
import org.fulib.docs.dtos.model.GenModel; | ||
|
||
// start_code_fragment: docs.dtos.GenDtos | ||
public class GenDtos implements ClassModelDecorator | ||
{ | ||
@DTO(model = GenModel.User.class, omit = { "id" }) | ||
class UserDto | ||
{} | ||
|
||
@DTO(model = GenModel.Address.class, pick = { "city", "street" }) | ||
class AddressDto | ||
{} | ||
|
||
@Override | ||
public void decorate(ClassModelManager m) | ||
{ | ||
// This omits PropertyChangeListeners etc. from the generated code | ||
m.getClassModel().setDefaultPropertyStyle(Type.POJO); | ||
m.haveNestedClasses(GenDtos.class); | ||
} | ||
} | ||
// end_code_fragment: |
Oops, something went wrong.