@MAPSTRUCT. No property named “packaging” exists in source parameter(s)

For those, who have the same issue when using mapstruct + lombok: I had the same issue. The reason was that I’ve been using Lombok plugin too. There’s no need to remove it, but you have to ensure that in pom.xml in <annotationProcessorPaths> Lombok tag is before the Mapstruct one. Example (part of pom.xml file): … Read more

How to use ModelMapper for deep inheritance objects?

Possible solutions: Have you tried to add the attribute type in the parent class? This should be enough if you retrieve this field from the DB. A simple tested trick, add protected String type = this.getClass().getSimpleName().toLowerCase();. Notice that it must be protected. Here’s my tested code: @Data abstract class A { protected String type = … Read more

C# MongoDB: How to correctly map a domain object?

It is possible to serialize/deserialize classes where the properties are read-only. If you are trying to keep your domain objects persistance ignorant, you won’t want to use BsonAttributes to guide the serialization, and as you pointed out AutoMapping requires read/write properties, so you would have to register the class maps yourself. For example, the class: … Read more

DTOs: best practices

I’ve been reading a few posts here regarding DTO’s and it seems to me that a lot of people equate them to what I would consider a ViewModel. A DTO is just that, Data Transfer Object – it’s what gets passed down the wire. So I’ve got a website and services, only the services will … Read more

Mapping Validation Attributes From Domain Entity to DTO

If you’re using something supporting DataAnnotations, you should be able to use a metadata class to contain your validation attributes: public class ProductMetadata { [NotEmpty, NotShorterThan10Characters, NotLongerThan100Characters] public string Name { get; set; } [NotLessThan0] public decimal Price { get; set;} } and add it in the MetadataTypeAttribute on both the domain entity & DTO: … Read more

Nullable reference type in C#8 when using DTO classes with an ORM

You can do either of the following: EF Core suggests initializing to null! with null-forgiving operator public string ServiceUrl { get; set; } = null! ; //or public string ServiceUrl { get; set; } = default! ; Using backing field: private string _ServiceUrl; public string ServiceUrl { set => _ServiceUrl = value; get => _ServiceUrl … Read more

Value Objects in CQRS – where to use

Ok I’ve changed my mind. I have been trying to deal with VOs a bunch lately and after watching this http://www.infoq.com/presentations/Value-Objects-Dan-Bergh-Johnsson it clarified a couple of things for me. Commands and Event are messages (and not objects, objects are data + behavior), in some respects much like DTOs, they communicate data about an event and … Read more

Should the repository layer return data-transfer-objects (DTO)?

Short answer: No. Long answer: repository is responsible for turning persisted data back to entities (models) and vice versa. Model is a business Model representing a business entity. DTO on the other hand – while looks like Model – is concerned with transfer of the object between various environment and in essence is a transient … Read more