Giter Site home page Giter Site logo

orika-spring-integration's Introduction

orika-spring-integration

Example on how to integrate Orika mapper into Spring in a very clean way.

OrikaBeanMapper (class)

This is the class you want to import into your project, or just copy-paste as it is, since, it works the same if you have zero or many custom mappers or converters.

It does two things:

  • Configures the Orika MapperFactory and factory builder.
  • Registers into the MapperFactory all CustomConverter and CustomMapper classes annotated with @Component.

To use it we just need to autowire it into the class and we'll be able to map any combination of classes with it:

@Autowired
private OrikaBeanMapper mapper;
private User user;

user = new User("Leo", "Messi", 28);
UserDto dto = mapper.map(user, UserDto.class);

Custom Mappers (example)

  • Create a class that extends CustomMapper whenever you need to customize the mapping between two classes.
  • Override mapAtoB and/or mapBtoA methods and implement the logic on how to map the attributes that need a specific way of being mapped. The fields not specified here will be mapped by default, i.e. matching by name and copying the value from one bean to the other.
  • Annotate the class with @Component so it can be discovered by OrikaBeanMapper.

Custom Converters (example)

  • Create a class that extends CustomConverter whenever you need to tell Orika how to convert a class type to another when a mapping is being done.
  • Implement convert method.
  • Annotate the class with @Component so it can be discovered by OrikaBeanMapper.

References

orika-spring-integration's People

Contributors

dlizarra avatar

Watchers

prateek goel avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.