It appears that Dozer will not map a Boolean property if the accessor of that property is defined as isProperty()
rather than getProperty()
.
The following groovy script illustrates the problem:
import org.dozer.*
class ProductCommand {
Boolean foo
}
public class ProductDto {
private Boolean foo;
public Boolean isFoo() { this.foo }
public void setFoo(Boolean p0) { this.foo = p0 }
}
def mapper = new DozerBeanMapper()
dto = new ProductDto(foo: true)
assert dto.isFoo()
ProductCommand mappedCmd = mapper.map(dto, ProductCommand)
assert mappedCmd.foo
The assertion on the final line fails. However, if I rename ProductDto.isFoo()
to ProductDto.getFoo()
it passes.
Is there a flag/option I can set in the Dozer mapping file that will instruct it to use either an is
or get
accessor for boolean properties? Alternatively, I could add a custom rule for every boolean property, but this is not very appealing.
Although the example above is written in Groovy, I've no reason to believe the same behaviour wouldn't be exhibited by the equivalent Java code.
These DTOs are generated by JAXB (which generates an "is" accessor, rather than a "get" accessor for booleans), so I can't rename the accessors. I'm using Dozer 5.3.2.
is
method has typeBoolean
- it mapsboolean isFoo()
methods fine. – Astrobiology