I'm using automapper v1.1 to map IDataReader to Dto. Seems it is doing case sensitive mapping. How can I config it to do case insensitive mapping? Thanks.
Found this: http://automapper.codeplex.com/workitem/6127
Related
I've just started using Jhipster for a simple project with a very simple datamodel (so far).
I have a question regarding the generated code for the one-to-many relationship:
Is it possible to generate with List instead of a Set, so I can have my child-items ordered?
If no, what is the best solution to solve my problem? I see 2 ways:
Change the generated code manually to use a List and then use liquibase (mvn liquibase:diff) to update my database ?
Have an attribute on the child-item to handle the order ?
What is the best way to handle the "problem" ?
Best regards
Martin Elkkjær
You can use the Spring #OrderBy annotation to sort your sets by the child entity. See http://www.objectdb.com/api/java/jpa/OrderBy
#Entity
public class Person {
...
#OrderBy("zipcode.zip, zipcode.plusFour")
public Set<Address> getResidences() {...};
...
}
I'd also recommend the following blog that explains how Sets/Lists differ for Hibernate and JPA: https://vladmihalcea.com/hibernate-facts-favoring-sets-vs-bags/ (where I found the answer originally)
A specification pattern can be used to compose objects as shown in the example below:
IUser user =
UserSpecification
.ForPerson()
.WithName("myname")
.WithSurname("mysurname")
.WithPrimaryContact(ContactSpecification.ForEmailAddress("abc#email.com"))
.AndNoMoreContacts()
.Build();
This leads to manually map the data from DTO to the specification object.
Is there a way, we can use automapper to fill object while using specification pattern? Does Automapper support this in any way?
Thanks
I don't think so, typically the specification pattern is used for piecemeal setting of individual properties. The implementation of the pattern involves for each method actually setting a property, by hand.
AutoMapper always maps from an object, in the above, I don't see a source object, just a specification. If the specification filled an object, then that object was mapped to the destination, then it would work. The result above from "Build()" could be mapped to "IUser".
Otherwise, it doesn't make much sense. The code inside a specification pattern is setting up an object, and trying to map this to AutoMapper configuration I think would be far more trouble/confusing than it would be worth.
I have a ton of domain entity to dto maps, that are basically one to one maps like this:
CreateMap<Package, PackageForm>();
I have to call CreateMap for each map, this seems like it could be handled by a convention or something. Is it possible to have AutoMapper (try to) create a mapping on the fly when Map() is called for a non-existing map?
Well I just discovered Mapper.DynamicMap(), seems to be what I was after.
I would like jpa annotations on my attributes, not on getter and setter. It is possible to configure hyperjaxb for this ?
I want this because I use lombok in order to avoid getter and setter code and have "#getter" "#setter" above attributes.
thank you
This is not supported out of the box at the moment (please file an issue if you need this functionality).
However you can do it by writing and overriding your own implementation of org.jvnet.hyperjaxb3.ejb.strategy.annotate.AnnotateOutline. See https://svn.java.net/svn/hj3~svn/trunk/ejb/tests/custom-naming/ for an example of overriding a strategy.
But be aware that Hyperjaxb has to use getters/setters to workaround some of the JAXB/JPA incompatibilities (for example simple type which is not supported by JPA). If you put annotations on fields, this won't work.
we're using Automapper (http://automapper.codeplex.com/) to map between entities and dto's. We have a situation where one property on an entity corresponds to three different properties on the dto, and we need to write some custom logic to do the mapping. Anyone know how we can do that? (We need to map both ways, from entity and from dto).
I notice that AutoMapper supports custom resolvers to do custom mapping logic, but as far as I can tell from the documentation, they only allow you to map a single property to another single property.
Thx
You can create a custom type converter. It allows you to define a converter for an entire type, not just a single property.