Coder Social home page Coder Social logo

Comments (8)

avurro avatar avurro commented on September 16, 2024 1

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.

avurro avatar avurro commented on September 16, 2024

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.

acron17 avatar acron17 commented on September 16, 2024

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.

avurro avatar avurro commented on September 16, 2024

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.

acron17 avatar acron17 commented on September 16, 2024

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.

avurro avatar avurro commented on September 16, 2024

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.

acron17 avatar acron17 commented on September 16, 2024

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.

vash95 avatar vash95 commented on September 16, 2024

Hi, i need a workaround, or elvis operation is now work?

from jmapper-core.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.