Dozer mapping

smackababy

Lifer
Oct 30, 2008
27,024
79
86
I don't normally ask questions here, but figured I'd give it a shot because nobody I work with can answer the question I have.

In Dozer is there a way to map an property of an object, or more specifically, exclude said property?

Here is what I am trying, and this is not working.
Code:
<mapping>
	<class-a>modelObject</class-a>
	<class-b>ObjectTO</class-b>
	<field-exclude type="one-way">
		<a>passedObject.objectIwantExcluded</a>
		<b>passedObject.objectIwantExcluded</b>
	</field-exclude>
</mapping>

Now, I believe my problem lies in them being named exactly the same, but I would prefer not to change that. I am really just trying to save on data being moved around, as there is no reason for me to be passing objectIwantExclude, because it contains a lot of information I otherwise don't need. My passedObject contains a lot of other fields I do need though.

I would also prefer not to use the wildcard = false method, due to having quite a few things being mapped properly already. I would also like to do something more elegant than making a custom-converter that just removes the information.

So, Dozer experts, am I missing something on how this is to be done, or can it just not be done this way? I have googled and the only things I can get to come up are the Dozer documentation, which isn't very helpful, and nothing else useful.

Thanks in advanced.

Update: Apparently, deep mapping does not work for objects, only fields. It works perfectly if I exclude a string or int from the passed object. Well, that is rather disappointing. =(
 
Last edited:

Tweak155

Lifer
Sep 23, 2003
11,448
262
126
Dang, I thought you were bringing back a character from The Matrix!

Kidding aside, why would you want to avoid naming the same item twice? Why exclude something twice? Logically that doesn't make sense.
 

smackababy

Lifer
Oct 30, 2008
27,024
79
86
Dang, I thought you were bringing back a character from The Matrix!

Kidding aside, why would you want to avoid naming the same item twice? Why exclude something twice? Logically that doesn't make sense.

The model and the TO have all the same properties, named the same. You are not excluding something twice. It is mapping the model properties to the TO properties. I, however, do not want to map a very specific part of that. Dozer is set up to automatically map those properties with the same name, so they do not require to be declared in the XML (or annotations, but we got enough of those already with Hibernate...).

In other cases, you would declare properties to be mapped to properties named something different, or otherwise you wouldn't have to declare them. You can do other things, like include custom converters and custom getters / setters if you can't do a direct mapping due to type.
 

Tweak155

Lifer
Sep 23, 2003
11,448
262
126
The model and the TO have all the same properties, named the same. You are not excluding something twice. It is mapping the model properties to the TO properties. I, however, do not want to map a very specific part of that. Dozer is set up to automatically map those properties with the same name, so they do not require to be declared in the XML (or annotations, but we got enough of those already with Hibernate...).

In other cases, you would declare properties to be mapped to properties named something different, or otherwise you wouldn't have to declare them. You can do other things, like include custom converters and custom getters / setters if you can't do a direct mapping due to type.

So in that event, is there a way to specify the argument further? I.E Model.passedObject.objectIwantExcluded and TO.passedObject.objectIwantExcluded?

Maybe dumb questions but I've never even heard of Dozer :(
 

smackababy

Lifer
Oct 30, 2008
27,024
79
86
So in that event, is there a way to specify the argument further? I.E Model.passedObject.objectIwantExcluded and TO.passedObject.objectIwantExcluded?

Maybe dumb questions but I've never even heard of Dozer :(

Well, no. Because I am mapping the two objects (the model and the TO). I just wish to exclude certain parts of the passedObject.
 

Tweak155

Lifer
Sep 23, 2003
11,448
262
126
Well, no. Because I am mapping the two objects (the model and the TO). I just wish to exclude certain parts of the passedObject.

Thinking from other language experience, if you're talking about a single object and excluding properties or sub objects of that object, I don't know how that would be technically possible without writing a method that does that.

So you're really trying to do this:

passedObject.objectIwantExcluded1
passedObject.objectIwantExcluded2

OR

passedObject1.objectIwantExcluded
passedObject2.objectIwantExcluded

OR

You're passing the same object twice - is this necessary?

I would focus on what would remove the ambiguity between the two excludes.
 

smackababy

Lifer
Oct 30, 2008
27,024
79
86
The <a> and <b> refer to what they are called on <class-a> and <class-b>. They are the same type.

I am mapping <a> to <b>. Since they have the relationship of a model / TO, it will automatically map all the properties that have the same name.