jmapper-framework / jmapper-core

Elegance, high performance and robustness all in one java bean mapper
http://jmapper-framework.github.io/jmapper-core
Apache License 2.0
227 stars 41 forks source link

convert primitiv to enum class #59

Closed l-salih closed 7 years ago

l-salih commented 7 years ago

ConversionBodyIllegalCodeException: error in static conversion: probably is an incompatibility of signature, the expected input fields do not match with the real ones, checks the configured class.

I want to convert a primitiv short to an enum object.

.add(attribute("anEnum") .value("aShort")) .add(conversion("shortToEnum") .from("aShort").to("anEnum") .type(JMapConversion.Type.DYNAMIC) .body("return com.test.v1.Enum.get(${source});")));

The class has a get() method which returns an Enum.

public enum Enum {

    NUMBER(1);

    private final int value;

    Enum(int value) {
        this.value = value;
    }

    public int getValue() {
        return value;
    }

    public static Enum get(short s){
        for(Enum e: values()){
            if(e.getValue() == s){
                return e;
            }
        }
        return null;
    }
}

maybe a Bug?

avurro commented 7 years ago

Hi @ls3642, I will write the test and give you feedback as soon as possible

avurro commented 7 years ago

Fixed!

<dependency>
  <groupId>com.googlecode.jmapper-framework</groupId>
  <artifactId>jmapper-core</artifactId>
  <version>1.6.1.CR2-SNAPSHOT</version>
</dependency>

You need to add the Snapshot repository! go to wiki page for this.

Add a star if you like the project! thank you for support! 👍

petromir commented 7 years ago

58 points 1.6.2-SNAPSHOT as a snapshot version. How 1.6.1.CR2-SNAPSHOT differs from it?

avurro commented 7 years ago

This snapshot includes several issue, see release notes for more info. For the first snapshot i haven't reasoned much about the definition of the name. This release include 1.6.2-SNAPSHOT, so you can use it without problem.

l-salih commented 7 years ago

Hi @avurro thanks for the fast response! I do get a Exception: com.googlecode.jmapper.exceptions.JMapperException: com.googlecode.jmapper.exceptions.ConversionBodyIllegalCodeException: There is an error in the generated method. Additional information: [source error] invalid types for !=

avurro commented 7 years ago

are you using the snapshot?

l-salih commented 7 years ago

I thought the snapshot version 1.6.2-SNAPSHOT also includes the fix of this bug. I used now the version 1.6.1.CR2-SNAPSHOT and it worked perfectly. Thank you for your support!

avurro commented 7 years ago

add a star if you like the project! thank you! :+1:

phil-schneider commented 7 years ago

We have the same issue. Could you create a new release for 1.6.1.CR2-SNAPSHOT We can not really work with Snapshot versions and I dont want to fork your whole project :-) Thanks a lot

avurro commented 7 years ago

I think about it a bit, let you know

petromir commented 7 years ago

I also vote for more often final releases, even if they contain 1 or 2 fixed issues. Thanks for your hard work.

phil-schneider commented 7 years ago

Hello, I cloned the repository to make a local release for 1.6.1.CR2-SNAPSHOT. But I did not find any commit for this issue, nor did I found any tags or branches for this. Could you please push your changes?

I understand that you might dont want to release yet, but please give us the chance to release a local version ourself with the fix. Thanks a lot.

avurro commented 7 years ago

@phil-schneider give me the time to release a version with this fix, just few hours.

avurro commented 7 years ago

I'm having problems with the tests, i am sorry for the delay

avurro commented 7 years ago

Ok guys, 1.6.1.CR2 released! i'm apologize for my delay