Get the App
SLTechnology News&Howtos  ›  Development  › 

An example Analysis of weird events occurred when MapStruct converts javaBean

Shulou Source: shulou.com Published: 2022-06-03 08:58:10 10月03日 Update

Editor to share with you the example analysis of strange events in MapStruct conversion into javaBean, I believe most people do not know much about it, so share this article for your reference, I hope you will gain a lot after reading this article, let's go to know it together!

MapStruct was used in the project, and I was particularly curious about its ability to convert JavaBean, because before, I used to use Vo to manually convert set, but when I came into contact with MapStruct, I felt that the previous way of using Vo was a bit low.

So I wanted to take a look and wrote a demo. So this weird time begins.

My code is as follows:

This is the pom file.

These are my two javaBean.

You can see the gray serialization interface because I ran it again and the converted JavaBean property was empty. I thought it was caused by serialization, so I removed it.

But it turns out that this is not the reason at all.

This is my mapper conversion class.

And my startup execution class.

The result of the correct operation should be like this

Now the result of my run is

This made me quite confused, so I checked a lot of bosses' blogs and said that adding "maven-compiler-plugin" configuration to pom would solve the problem, so I configured it.

As follows:

The gray one is to see that some bosses talk about such a configuration. Before, my maven-compiler-plugin was version 3.8, but it just made it the way it is now, but it still doesn't seem to be of any use.

After running, the property is empty, and I try maven-clean and maven-instell, and in a lot of my attempts, I suddenly find that after changing the method name of that transformation after install, the conversion can be successful, and the property has a value.

I looked at the execution process through debug. There was no set method generated in the implementation class of mapper before I did not change the method name, but after I changed it, I generated the set method, which is the direct reason why the property is null.

I have tried a lot of methods, read a lot of materials and did not understand why there is such a problem, distressed "ah!"

I changed this method after packing.

As long as you change this construction method, it can be realized.

The above is all the contents of the article "sample Analysis of strange events occurred when MapStruct converts javaBean". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Method property run weird way article result this is boss try configure event example time out analysis content reason that is sequence generate Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Xiaomi MariaDB macOS Huawei