Comments (8)
I am going to implement the functions mentioned above, after a some study, i will decide if include this features with this release or not (giving priority to default values).
The next comment will be to share the release date.
Your interest is really appreciated, thank you!
from jmapper-core.
Hi,
thank you for support!
Your proposal is interesting, in this case to find a solution is important search between existing standards.
I think that an Elvis operator is the best response for this need, for example:
<attribute name="something">
<value name="${some?.thing}" />
</attribute>
as for Elvis operator, if one of variables is null, destination will be null.
What do you think about?
from jmapper-core.
Hi avurro,
thanks for the quick response!
I like your approach to check for existing standards first. However I am not sure if this is the best of all solutions as it doesn't give users the option to chose their own default value (like an empty string in my case). This is inconvenient to me but will give users real trouble who have primitive attributes in their target objects.
For my personal issue I think I could live with null values in the target object (I am aiming for some datastructure mapping between different database structures), as I think I could insert the null values into the db instead of empty strings. I however would favor a solution with the mentioned flexibility.
Kind regards acron
from jmapper-core.
Default values are a second feature that will be implemented, because it is useful.
For this proposal, i think that a solution may be:
private class Destination{
@JMap("${some?.thing}")
private String field = ""; // default value
// getter and setter..
}
mapping code:
JMapper<Destination, Source> = mapper<>(Destination.class, Source.class);
Source source = new Source();
mapper.getDestination(source, MappingType.ONLY_VALUED_FIELDS);
In this case if source is null, destination field will not change. Or in case of enrichment:
mapper.getDestination(destination, source, MappingType.ALL_FIELDS, MappingType.ONLY_VALUED_FIELDS);
It's a viable solution for you?
from jmapper-core.
Thanks again for your quick response!
It's a viable solution for you?
Honestly I don't know yet. I don't can set the default value in the way you suggest, as the target classes are generated. Maybe the Java default values (null for objects, 0 and similar for primitive types) will suffices, maybe not. (See below for details on what I actually am trying to achieve).
Boring(?) details:
My (maybe somewhat special) use case is as follows:
I want to generate two different sets of classes from two distinct database structures. I than want to use a mapping framework (JMapper ;-) ) to map from objects from the first datastructre to the objects of the second one. As the classes are generated from the tables in a DB I want to configure the whole mapping in XML as these files won't be overwritten when re-generating the classes (which already works... although I am at a pretty early stage of the project).
from jmapper-core.
In this case a combination of Elvis operator and default value is for you.
In the middle time, have you need a workaround?
from jmapper-core.
Again (at least for me) being able to set the default value through JMapper would be more convenient as I won't be able to generate the target classes with custom default values (e.g. "", or even "null" instead of null for strings).
Thanks for asking, no I don't need a workaround. I however would be happy to (alpha/beta) test your implementation (once done) against my use case. Just give me the word if you like.
from jmapper-core.
Hi, i need a workaround, or elvis operation is now work?
from jmapper-core.
Related Issues (20)
- Quarkus JMapper error in mapper constructor
- mapping between nested fields
- Different code in maven central HOT 4
- Function to compare
- JMapper with java 9 modules
- Update xstream dependency
- How can I map encapsulated complex types? HOT 1
- Using operators in API body
- mapper from autogenerated class HOT 2
- Map element from Array to another Array element
- How to map single object to nested object
- Mapping nested class
- Mapping List<String> to a List of non-String data type HOT 1
- How to do Index Mapping
- Nested mapping in source and destination
- Is this project still maintained? HOT 3
- Mapping a flat source to a nested destination not working
- JMapper with Lambok HOT 1
- [Question] Nested object mapping/conversion not working HOT 3
- Breaks with XStream 1.4.18
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jmapper-core.