Sometimes it needs to have more than one mapping between the same classes. For example, there are two external systems with different security rights. They use the same class we expose to them. The first of them can access all it needs about the state of an object and a part of an object's state should be exposed to the second.
Nomin can help us supporting mapping cases. Mapping case identifier can be defined during defining mapping sides as shown.
mappingFor a: Person, b: Employee // defining default mapping case mappingFor a: Person, b: Employee, case: "secured" // defining mapping case "secured" mappingFor a: Person, b: Employee, case: 1 // defining mapping case 1 mappingFor a: Person, b: Employee, case: 2 // defining mapping case 2 and so on
No matter what to use as a particular mapping case identifier, it should have properly implemented equals method. Using mapping cases is simple as the rest of Nomin's API.
Employee e = nomin.map(person, Employee.class, "secured");
During mapping complex properties you can specify what is the mapping case Nomin should use when performing conversions.
mappingFor a: Person, b: Employee a.children = b.kids mappingCase "mapOnlyNames"
So Nomin will use the mapping with specified mapping case identifier.
Let's assume that we have no knowledge during writing a mapping what is the mapping case we should use. For instance, the mapping case depends on the configuration. Nomin provides the ability to dynamically specify a mapping case identifier, you probably expect this, as a Groovy closure :)
mappingFor a: Person, b: Employee a.children = b.kids mappingCase { if (configuration.mode == FULL_COPY) "fullCopy"; else "partialCopy }
If the closure returns null the default mapping case will be used. Please refer Groovy documentation about Closure's return value.