How to exclude a property of a nested multi-occurance element.
See original GitHub issueI have two classes: A
and B
.
A has a property items
which is a collection of B
, when mapping I would like to exclude the id property of A
and of all B
items. How can I achieve it? The closest thing I found in the user guide is the names{fullName}
example when working with nested multi-occurrence elements (nothing on exclusion though) - so I tried to do something similar to exclude the id of B
but it results in the exclusion of the entire items property (needless to say that A’s id gets excluded properly).
@Entity
public class A {
@Id
@GeneratedValue
private Long id;
//...
@OneToMany()
@JoinColumn(name = "a_id")
private Set<B> items;
// getters and setters
}
@Entity
public class B {
@Id
@GeneratedValue
private Long id;
//...
public B() {}
// getters and setters
}
MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();
mapperFactory.classMap(A.class, A.class)
.mapNulls(true)
.exclude("id")
.exclude("items{id}")
.byDefault()
.register();
MapperFacade mapperFacade = mapperFactory.getMapperFacade();
A dest = mapperFacade.map(source, A.class);
Issue Analytics
- State:
- Created 6 years ago
- Comments:9 (4 by maintainers)
Top Results From Across the Web
exclude nested children - jquery - Stack Overflow
The idea is to remove any inputs, selects, or textareas, which have a closest parent other than your desired parent. Notice also that...
Read more >Exclude - Rocket Software Documentation
In a static server page, exclude the field or entity if it does not need to be sent to the ... Entity and...
Read more >Select layers and objects – Figma Help Center
Select all layers. The Edit menu allows to select multiple objects based on their properties. This allows you to select all layers in...
Read more >JSON methods, toJSON - The Modern JavaScript Tutorial
The space argument is used exclusively for a nice output. Here space = 2 tells JavaScript to show nested objects on multiple lines,...
Read more >9 Subsetting R Objects | R Programming for Data Science
The [ operator can be used to extract multiple elements of a vector by ... can take an integer sequence if you want...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’ve successfully achieved my goal using your suggestion to create a custom class map builder, it is much more convenient than my attempted workaround. I will post Gist later this week.
So basically you want to exclude id everywhere ? to do that you need to create a custom class map builder with a custom byDefault method.
https://gist.github.com/elaatifi/5212119
here is an example of how to create custom class map builders, for instance this one is supporting annotations, but you can provide your own rules : exclude id fields or any other generic rule.