Skip to main content

Why Dozer Framework (Bean Manipulation)

Why Dozer ?


Let us think about a situation that you have a source bean which contains lot of fields and the source bean belongs to a different project or module. Now you want to expose the bean to 
the outside world as a part of your web service REST service development. It is not advisable to do it. There may be the following reasons.
  • The source bean is not serialized and a final class.
  • The source system does not allow doing it because of security breach.
  • The source bean is very heavy and contains lot of nested beans.
  • The source bean has fields of different types which may not be required for other system.
  • The source bean has lot of fields; some of them are not required.

Scenario to use Dozer


Suppose You want to make a REST call or web service call to get the minimal account details of a person. But the source system has a bean called “Acc0untBean” which contains many sensitive information like person’s internet banking passw0rd, PAN no or social security number, total balance etc. You want to develop an application where you want to expose only account’s address details, name and home branch of the bank. This is a required situation where you want to have your custom defined bean which should be exposed to outside based upon the account number. In this case you have to copy the original bean to your custom defined bean. To achieve this functionality you can do it in the following ways : 

  • Use java Reflection or Introspection utility to copy from source to destination bean.
  • Write code to manually copy the contents of the source bean to destination bean.
  • Use an available framework which does the copy automatically.
In This scenario we can use framework called 'Dozer'. Dozer Framework can be used for : 
  • Copy collections
  • Copy source Plain/Flat bean to destination Plain/Flat bean
  • Copy flat bean to nested bean and vice versa
  • Bi-directional bean copy
  • Copy bean with custom conversion.

Lets Understand By Code 

Source POJO class : 

package com.snjv.dozer.src;

public class User {

private String name;
private int age;
private Address adrs;

// All getter and setters methods below 


}


package com.snjv.dozer.dst;

public class User {

private String name1;
private int age1;
private Address1 adrs1;

// All getter and setters methods below 

}

Dozer mapping file called "dozerMapping.xml"

<?xml version="1.0" encoding="UTF-8"?>
<mappings xmlns="http://dozer.sourceforge.net" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://dozer.sourceforge.net http://dozer.sourceforge.net/schema/beanmapping.xsd">
<mapping map-id="a">
<class-a>com.snjv.dozer.src.User</class-a>
<class-b>com.snjv.dozer.dst.User1</class-b>
<field>
<a>name</a>
<b>name1</b>
</field>
<field>
<a>age</a>
<b>age1</b>
</field>
<field>
<a>adrs.doorNo</a>
<b>adrs1.doorNo1</b>
</field>
<field>
<a>adrs.stName</a>
<b>adrs1.stName1</b>
</field>
</mapping>
</mappings>

The above xml configuration file <class-a > refers to source bean and < class-b> refers to destination bean. The other field <a> refers to the property of source bean and <b> refers to the property of the destination bean.

It's done, it looks very simple and provides many powerful Features. Following few things for bean copy using "Dozer" framework need to take care.
  • Source bean
  • Destination bean
  • Dozer mapping file configuration
  • Mapping configuration should contain source POJO class with proper package name
  • Mapping configuration should contain destination POJO class with proper package name
  • Mapping configuration should have proper exact property name what you have defined in         the java class

Copy Custom Data Type  :

package com.snjv.dozer.collection.src;

public class Address {

        private String name;

private String doorNo;
private String stName;
private String countryName;

}



package com.snjv.dozer.collection.src;

public class AddressList {

/** The address list. */
private List<Address> adrsList;

public List<Address> getAdrsList() {
return adrsList;
}

public void setAdrsList(List<Address> adrsList) {
this.adrsList = adrsList;
}

}

In Above class the list contains list of Address type objects. Let us learn how to achieve.

First of all create a mapping between Address objects from source to destination and then create a mapping between source list to destination list. 
Let us see the mapping configuration file


<?xml version="1.0" encoding="UTF-8"?>
<mappings xmlns="http://dozer.sourceforge.net"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://dozer.sourceforge.net http://dozer.sourceforge.net/schema/beanmapping.xsd">
      
      <mapping map-id="k">
<class-a>com.snjv.dozer.collection.src.Address</class-a>
<class-b>com.snjv.dozer.collection.dst.AddressBean</class-b>
<field>
<a>name</a>
<b>name</b>
</field>
<field >
<a>id</a>
<b>id</b>
</field>
</mapping>
<mapping map-id="q1" type="one-way" relationship-type="non-cumulative">
<class-a>com.snjv.dozer.collection.src.AddressList</class-a>
<class-b>com.snjv.dozer.collection.dst.AddressBeanList</class-b>
<field map-id="k">
<a>adrsList</a>
<b>adrsList</b>
</field>
</mapping>
      
</mappings>


To copy the list object, you can use the same code above.

Copy flat bean to nested bean and vice versa. Lets see the changed required in configuration file



<?xml version="1.0" encoding="UTF-8"?>
<mappings xmlns="http://dozer.sourceforge.net"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://dozer.sourceforge.net http://dozer.sourceforge.net/schema/beanmapping.xsd">
      
      <mapping map-id="a">
<class-a>com.snjv.dozer.src.User</class-a>
<class-b>com.snjv.dozer.dst.User1</class-b>
<!-- Other field info -->
<field>
<a>doorNo</a>
<b>adrs1.doorNo1</b>
</field>
<field>
<a>stName</a>
<b>adrs1.stName1</b>
</field>
<field>
<a>cname</a>
<b>countryName</b>
</field>

</mapping>
      
</mappings>


Configuration based mapping provides the following benefits.
  • You can add the property in the java class as and when required.
  • You can change the property name as and when required and it does not require to build the application.
  • You can edit and remove the mapping as and when required.
  • You can have one or many property files for specific requirements.
  • You can also configure the mapping in Spring application ie spring configuration file.

I hope you have enjoyed this small post on DOZER Framework.


Enjoy !!!!!!


Comments

  1. Its as if you had a great grasp on the subject matter, but you forgot to include your readers. Perhaps you should think about this from more than one angle. areas to invest in property uk

    ReplyDelete
  2. I am looking for and I love to post a comment that "The content of your post is awesome" Great work! areas to invest in property uk

    ReplyDelete
  3. Therefore, these scientists are earning much more money than their counterparts in other IT positions. For instance, a good professional In India earns an annual salary of ₹650,000. And the good thing is that this is more than the national average for professionals in other fields, such as software engineers. data science course in hyderabad

    ReplyDelete
  4. Wow, cool post. I'd like to write like this too - taking time and real hard work to make a great article... but I put things off too much and never seem to get started. Thanks though. 11 best freelance hire an app developer

    ReplyDelete
  5. Yes i am totally agreed with this article and i just want say that this article is very nice and very informative article.I will make sure to be reading your blog more. You made a good point but I can't help but wonder, what about the other side? !!!!!!Thanks power harrow

    ReplyDelete
  6. This looks like thoroughly perfect. Every one of these bit of material happen to be fabricated in conjunction with loads of past material. I prefer the fact that considerably. Best Smart contract Development company chennai

    ReplyDelete
  7. I’m going to read this. I’ll be sure to come back. thanks for sharing. and also This article gives the light in which we can observe the reality. this is very nice one and gives indepth information. thanks for this nice article...
    Custom MLM Software jaipur

    ReplyDelete
  8. Great Post…This Article is very unique. Thanks for sharing and very informative!!!MLM Software Service Provider Mumbai

    ReplyDelete
  9. You there, this is really good post here. Thanks for taking the time to post such valuable information. Quality content is what always gets the visitors coming. taxibus bestellen

    ReplyDelete
  10. fantastic artical.thanks for a sharing and i read this blog..gupt rog doctors in allahabad

    ReplyDelete
  11. Amazing Article ! I would like to thank you for the efforts you had made for writing this awesome article.sexologist Doctors

    ReplyDelete
  12. Wonderful blog! I found it while surfing around on Yahoo News. Do you have any suggestions on how to get listed in Yahoo News? I’ve been trying for a while but I never seem to get there! Appreciate it. i99pro

    ReplyDelete
  13. An fascinating discussion is value comment. I think that it is best to write extra on this matter, it won’t be a taboo topic however generally people are not enough to talk on such topics. To the next. Cheers 바카라사이트

    ReplyDelete
  14. Hi there! Nice post! Please tell us when I will see a follow up! 메이저사이트

    ReplyDelete
  15. Pretty nice post. I just stumbled upon your weblog and wanted to say that I have really enjoyed browsing your blog posts. After all I’ll be subscribing to your feed and I hope you write again soon! windows 10 activator txt

    ReplyDelete
  16. Hi there! Nice post! Please tell us when I will see a follow up! free nrp certification online

    ReplyDelete
  17. Took me time to read all the comments, but I really enjoyed the article. It proved to be Very helpful to me and I am sure to all the commenters here! It’s always nice when you can not only be informed, but also entertained! southfreak

    ReplyDelete
  18. Pretty good post. I have just stumbled upon your blog and enjoyed reading your blog posts very much. I am looking for new posts to get more precious info. Big thanks for the useful info. best digital perm

    ReplyDelete
  19. Hey, this day is too much good for me, since this time I am reading this enormous informative article here at my home. Thanks a lot for massive hard work. ufa800.com

    ReplyDelete
  20. Thanks for the blog filled with so many information. Stopping by your blog helped me to get what I was looking for. Now my task has become as easy as ABC. know more

    ReplyDelete
  21. That is the excellent mindset, nonetheless is just not help to make every sence whatsoever preaching about that mather. Virtually any method many thanks in addition to i had endeavor to promote your own article in to delicius nevertheless it is apparently a dilemma using your information sites can you please recheck the idea. thanks once more. iflix

    ReplyDelete
  22. Good website! I truly love how it is easy on my eyes it is. I am wondering how I might be notified whenever a new post has been made. I have subscribed to your RSS which may do the trick? Have a great day! matka chart

    ReplyDelete
  23. Hello I am so delighted I located your blog, I really located you by mistake, while I was watching on google for something else, Anyways I am here now and could just like to say thank for a tremendous post and a all round entertaining website. Please do keep up the great work. matka

    ReplyDelete
  24. Thanks for the blog loaded with so many information. Stopping by your blog helped me to get what I was looking for. 에볼루션카지노

    ReplyDelete
  25. Your blog is too much amazing. I have found with ease what I was looking. Moreover, the content quality is awesome. Thanks for the nudge! 먹튀검증

    ReplyDelete
  26. Positive site, where did u come up with the information on this posting?I have read a few of the articles on your website now, and I really like your style. Thanks a million and please keep up the effective work. 무료릴게임

    ReplyDelete
  27. This is a truly good site post. Not too many people would actually, the way you just did. I am really impressed that there is so much information about this subject that have been uncovered and you’ve done your best, with so much class. If wanted to know more about green smoke reviews, than by all means come in and check our stuff. artisan couvreur Chantilly

    ReplyDelete
  28. Great articles and great layout. Your blog post deserves all of the positive feedback it’s been getting. pussy888

    ReplyDelete
  29. I am unable to read articles online very often, but I’m glad I did today. This is very well written and your points are well-expressed. Please, don’t ever stop writing. 먹튀검증커뮤니티

    ReplyDelete
  30. Hi there! Nice stuff, do keep me posted when you post again something like this! ceme online

    ReplyDelete
  31. Merely a smiling visitant here to share the love (:, btw outstanding style. hotmail.com

    ReplyDelete
  32. Hi there! Nice stuff, do keep me posted when you post again something like this! ADT

    ReplyDelete
  33. Great post, you have pointed out some fantastic points , I likewise think this s a very wonderful website. Sattamataka143

    ReplyDelete
  34. Cool stuff you have got and you keep update all of us. Moviesda

    ReplyDelete
  35. Great articles and great layout. Your blog post deserves all of the positive feedback it’s been getting. BSNL Broadband Plans

    ReplyDelete
  36. Someone Sometimes with visits your blog regularly and recommended it in my experience to read as well. The way of writing is excellent and also the content is top-notch. Thanks for that insight you provide the readers! order packwoods marathon Gummies

    ReplyDelete
  37. Good website! I truly love how it is easy on my eyes it is. I am wondering how I might be notified whenever a new post has been made. I have subscribed to your RSS which may do the trick? Have a great day! best merchant services to work for

    ReplyDelete
  38. I really like your writing style, great information, thankyou for posting. buy youtube views non drop

    ReplyDelete
  39. Merely a smiling visitant here to share the love (:, btw outstanding style. How do I get rid of my dull looking hair

    ReplyDelete
  40. Cool stuff you have got and you keep update all of us. joker388

    ReplyDelete
  41. Hi there! Nice stuff, do keep me posted when you post again something like this! research transcription services

    ReplyDelete
  42. I really like your writing style, great information, thankyou for posting. 먹튀검증

    ReplyDelete
  43. Very good points you wrote here..Great stuff...I think you've made some truly interesting points.Keep up the good work. 88카

    ReplyDelete
  44. Interesting and amazing how your post is! It Is Useful and helpful for me That I like it very much, and I am looking forward to Hearing from your next.. 88카

    ReplyDelete
  45. Most patients want to have liposuction done by a specialist. A liposuction specialist is someone who performs this procedure almost daily. about his

    ReplyDelete
  46. liposuction is the most common cosmetic surgical procedure performed because it works, and the results are dramatic, particularly for the right patients. But are you a good candidate for liposuction? informative post

    ReplyDelete
  47. Thankyou for this wondrous post, I am glad I observed this website on yahoo. 123movie

    ReplyDelete
  48. What a thrilling post. It is extremely chock-full of useful information. Thanks for such a great info. 토토사이트

    ReplyDelete
  49. An interesting dialogue is price comment. I feel that it is best to write more on this matter, it may not be a taboo topic however usually individuals are not enough to talk on such topics. To the next. Cheers. 먹튀검증

    ReplyDelete
  50. The biggest reason for the increase in the number of scam sites is when the Toto site is opened indiscriminately without a start-up fee, and the exchange rate is high even with a low charging rate. There are many parts that are difficult for regular members to verify. Please try with Sports Toto Nice. 먹튀검증

    ReplyDelete
  51. Amazing Article ! I would like to thank you for the efforts you had made for writing this awesome article.......Best Sexologist in Prayagraj

    ReplyDelete
  52. Thankyou for this wondrous post, I am glad I observed this website on yahoo. บาคาร่าออนไลน์

    ReplyDelete
  53. thanks for the tips and information..i really appreciate it.. 토토사이트

    ReplyDelete
  54. RSJ is at the top of our game when it comes to tax-minimization strategies for asset growth, protection and transfer. We have always known that something was missing from traditional estate planning for high-net-worth families. this hyperlink

    ReplyDelete
  55. It meets all the demands which a farmer required within the tractor. It's the best steering with hydrostatic power, which is easy to handle. Massey Ferguson 375 is the only tractor of its kind within the market and has a unique style. Massey Ferguson 385 4wd For Sale in Botswana

    ReplyDelete
  56. Your blog has piqued a lot of real interest. I can see why since you have done such a good job of making it interesting. I appreciate your efforts very much. Massey Ferguson 240 for sale

    ReplyDelete
  57. Positive site, where did u come up with the information on this posting?I have read a few of the articles on your website now, and I really like your style. Thanks a million and please keep up the effective work. togel singapore

    ReplyDelete
  58. Took me time to read all the comments, but I really enjoyed the article. It proved to be Very helpful to me and I am sure to all the commenters here! It’s always nice when you can not only be informed, but also entertained! 대전건마

    ReplyDelete
  59. Yes i am totally agreed with this article and i just want say that this article is very nice and very informative article.I will make sure to be reading your blog more. You made a good point but I can't help but wonder, what about the other side? !!!!!!Thanks ฉีดฟิลเลอร์คาง อันตรายไหม

    ReplyDelete
  60. Awesome article! I want people to know just how good this information is in your article. It’s interesting, compelling content. Your views are much like my own concerning this subject. textbook answers

    ReplyDelete
  61. I'm enthusiastically keeping on the web for storys that can oblige me. There is actually a substitute to understand about this. I feel you made enduringly acceptably hardly any salubrious obsessions in Attributes also. Tie included, epic calling! myopia correction lens

    ReplyDelete
  62. Mmm.. destroying to be here in your report or urge, whatever, I reputation I should other than plan strong for my have site need I play some salubrious further reestablished pulled in with your general zone. https://www.buyyoutubeviewsindia.in/youtube-marketing/

    ReplyDelete
  63. It's chief, finally , take a gander at material at the street address. 카지노사이트

    ReplyDelete
  64. I cannot wait to dig deep and kickoff utilizing resources that I received from you. Your exuberance is refreshing. 꽁머니 3만

    ReplyDelete
  65. hey there and thank you for your information – I’ve definitely picked up something new from right here. I did however expertise a few technical issues using this website, since I experienced to reload the web site lots of times previous to I could get it to load properly. I had been wondering if your web hosting is OK? Not that I’m complaining, but sluggish loading instances times will often affect your placement in google and could damage your high-quality score if advertising and marketing with Adwords. Well I’m adding this RSS to my email and could look out for a lot more of your respective fascinating content. Ensure that you update this again very soon.. 먹튀검증

    ReplyDelete
  66. I wanted to thank you for this excellent read!! I definitely loved every little bit of it. I have you bookmarked your site to check out the new stuff you post. 토토사이트

    ReplyDelete
  67. When you use a genuine service, you will be able to provide instructions, share materials and choose the formatting style. Lottery Sambad

    ReplyDelete
  68. Nice to be visiting your blog again, it has been months for me. Well this article that i’ve been waited for so long. I need this article to complete my assignment in the college, and it has same topic with your article. Thanks, great share. 오피사이트

    ReplyDelete
  69. Excellent post. I certainly appreciate this website. Keep writing! sexologist course in allahabad

    ReplyDelete
  70. Great post, you have pointed out some fantastic points , I likewise think this s a very wonderful website.sexologist Doctors

    ReplyDelete
  71. Looking for answers to your CBD questions? Weed Viral is here to help you get the accurate, evidence-based information you need.

    ReplyDelete
  72. Your Blog is very nice.
    Wish to see much more like this. Thanks for sharing your information
    Buy Peripherals Online at Best Prices | MyBogo | Free Shipping

    ReplyDelete
  73. I have bookmarked your blog, the articles are way better than other similar blogs.. thanks for a great blog! gupt rog in allahabad

    ReplyDelete
  74. Dental, the emergency dental serving for the greater Houston area. Our dedicated team will do their best to get you an appointment for the same day as soon as possible. Emergency Dental Center

    ReplyDelete
  75. The end product is generally insufficient and a waste of money. An automated system simply cannot consider and properly advise you how to best optimize a website for your specific market and objectives. To accomplish that, you need a qualified and breathing human in the process. britishart yale edu

    ReplyDelete
  76. i really try these steps its very helpful to me , thanks for this amazing blog .sexologist Doctors

    ReplyDelete
  77. Good website! I truly love how it is easy on my eyes it is. I am wondering how I might be notified whenever a new post has been made. 사설토토

    ReplyDelete
  78. Good website! I truly love how it is easy on my eyes it is. I am wondering how I might be notified whenever a new post has been made. muktisugar.com

    ReplyDelete
  79. Very well written article. It was an awesome article to read. Read more info about double girder crane. Complete rich content and fully informative. I totally Loved it.

    ReplyDelete
  80. You have provided valuable data for us. It is great and informative for everyone.Read more info about tire shredders for sale Keep posting always. I am very thankful to you.

    ReplyDelete
  81. A very delightful article that you have shared here. Your blog is a valuable and engaging article for us, and also I will share it with my companions who need this info, Online Workplace Safety Training Thankful to you for sharing an article like this.

    ReplyDelete
  82. I generally check this kind of article and I found your article which is related to my interest. Genuinely it is good and instructive information, Overhead Crane Training Ontario Thankful to you for sharing an article like this.

    ReplyDelete
  83. "I recently had to replace my old water pump , and I was amazed at how much of a difference it made in my plants' health and growth. The new pump I installed was more efficient and powerful, which meant my plants were getting the right amount of water at the right time. It's amazing what a difference the right water pump can make!"

    ReplyDelete

Post a Comment

Thanks for your concern.

Popular posts from this blog

JAVA_OPTS Variable Details

Memory Available to the Java JVM Increasing the memory available to the Java JVM JAVA_OPTS="-Xmx1024m -Xms256m" export JAVA_OPT Options description: -Xmx sets the maximum amount of memory that can be allocated to the JVM heap; here it is being set to 1024 megabytes. -Xms sets the initial amount of memory allocated to the JVM heap; here it is being set to 256 megabytes. Run Java JVM in Server Mode The Java JVM can optimize a number of things for server environments. You can explicitly select the Java HotSpot Server VM with the -server option. JAVA_OPTS="-Xmx1024m -Xms256m -server" export JAVA_OPT What the option means: -server instructs the launcher to use the Java HotSpot Server VM. PermGen Memory If you start getting java.lang.OutOfMemoryError: PermGen space error messages. You may want to include a "-XX:MaxPermSize" option in your JAVA_OPTS. JAVA_OPTS="-Xmx1024m -Xms256m -server -XX:MaxPermSize=128m" export

Difference between Micro Service and Web Services

Micro web services and Web services are two different concepts of application development architecture, Which can be differentiated from it's development style and layered architecture.In This article I will explain the difference between Web Services and Micro Services Web Services ? Web services are services that are made available from a business's Web server for Web users or other Web-connected programs. it is a way to expose the functionality of an application to other application, without a user interface. It is a service which exposes an API over HTTP. Web Services allow applications developed in different technologies to communicate with each other through a common format like XML, Jason, etc.  Web services are not tied to any one operating system or programming language. For example, an application developed in Java can be used in C#, Android, Php etc., and vice versa.  Web Service is a connection technology, a way to connect services together into a S