I am using Dozer mapping. i have two pojo1 and pojo2. pojo1 values to be mapped to pojo2. Pojo1 has 3 properties and Pojo2 has 4 properties. i am able to map 3 properties form pojo1 to pojo2 but to map fourth property i dont have property in pojo1. to map fourth property i cannot take value from pojo1, directly i need to give the value by taking from Enum. Please help me is it possible to give value to any property through mapping file?
value from enum directly not from pojo1
fourth property
Thanks!
As far as I know this is not possible in a convenient way. The only way to do this atm is by either having a custom converter, or by modifying one of the POJOs.
With a custom converter you could just map pojo1.field3 to pojo2.field4. The converter completely ignores pojo1.field3, and just sets the pojo2.field4 to your enum value.
Another solution is to just modify pojo1 and add a field4 which always returns the enum value.
And the third solution is to modify pojo2, and just set field4 in the default constructor. If you can't modify the default constructor, you can use a custom create method or a custom bean factory to achieve the same.
I've been doing dozer mappings a lot, and would like some more convenient solution for this too. Unfortunately I don't think there is any atm.
Let me know how it works out for you!
Related
I have a class named "Project" with attribute "Name" having type of String. I have changed it from Allow Null=True to False and then I have saved the model and restarted the WECPOF prototyper in xml mode. But it still allows me to create and save instances of Project without adding a name. What might I be doing wrong?
Try to keep your attributes "nullable", i.e. Allow null = True. Why? Because you usually end up wanting to see the difference between "nothing" and "empty".
As Hans suggested, add a contraint on the class with a expression like this "not self.Name.isNullOrEmpty".
I guess the string is not null but empty "". Strings are tricky that way - the only type that is presented the same as null and as its simplest possible value.
To signal to user that you do not allow a null or empty you can do a constraint on the class or add a validation expression in the ViewModel.
I'd like to copy all properties from a NSManagedObject over to a "regular" Swift class. I don't want to do this manually, i.e. make a regular class with all the properties for every NSManagedObject and then manually copy all those values.
I do know how to read property names and values dynamically from my managed object, but how to set them on a Swift class in a way that I can then use those values like
mySwiftObject.name
which returns a String or
mySwiftObject.age
which returns a Number (as those are the types on the Managed Object). Custom subscripting and stuff like that came to my mind, but I didn't manage to achieve this... Is there a nice way to do exactly that?
I am using spring batch to read pipe (| delimited) separated file which have have 7 field. I created a class called MyLineMapper that extends spring's FieldSetMapper. This class maps field values provided in file to my object (XYZ type). Now the problem is that fieldSet object that i get inside class extending FieldSetMapper contain empty value for field that are not present in delimited values.
For example:
Suppose that the delimited file format is as follows: |ID|Country|City|Pin|
Suppose i provide following line in file: |1|India|
As you can see the above line does not contain information for City and Pin. Therefore, I expect FieldSet object should contain Null value for these two fiels (City and Pin) instead of empty string. I don't want empty value as Null will help me to know if that field was actually present in file or not.
How can I achieve this ? Do I need to extend DelimitedLineTokenizer which I am using for tokenizing ? Or this is a simple way to do this ?
Any help will be appreciated.
From FieldSetMapper javadoc
To customize the way that FieldSet values are converted to the desired
type for injecting into the prototype there are several choices. You
can inject PropertyEditor instances directly through the customEditors
property, or you can override the createBinder(Object) and
initBinder(DataBinder) methods, or you can provide a custom FieldSet
implementation.
Depending on type of your target bean conversion is done using default Spring convention. If you need other type of logic write your own.
So, I have a core expression. It has a with element that retrieves my variable (successfully). Say my variable is of type java.awt.Point; thus it has two public properties, x and y. Is there any way to test against these properties in a core expression?
If there was some way I could provide my own implementation of org.eclipse.core.expressions.Expression, that would work. Is that possible?
I think you can do this by creating a propertyTester that would react properly to your variable using your custom code.
I have a little bit of a curve ball for you. Maybe just a design issue...maybe even something as simple as me not understanding Data annotation providers.
Anyway here we go:
I have a class which represents some model data. Let's say it represents a package/box/carton.
It actually represents all of these things so I use the class in several different views. Sometimes I want the attribute of the field Package_Description to be
So that it shows up as Box Number : input box here.
Now if i want it to appear as "Carton Name" my only option would be to sub type it. Or use a separate class to have the annotations for this class. My quandary is that some of the field names are user configurable and therefore I cannot have a static definition!
(By the way i am using third party librarys [Telerik MVC Grid] do display these field names so i cannot change the fact that it's looking at data annotation )
So I just need to know is there a way to add attributes dynamically?
Create an anonymous type on the fly, sub class the original and then add attributes using reflection?
Or what other options are open to me, do I need to somehow implement a different annotation provider?
Attributes are part of the definition of the type. Because of that, you can't modify attributes of existing classes during runtime.
You could create a new type during runtime (not an anonymous type), but I think that's not such a good idea. I'm sure whatever component you're using, it allows you to specify the appearance explicitly.