Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BigDecimal conversion problem - morphia 1.3 - MongoDB 3.4 #1093

Closed
jorge-tautz opened this issue Dec 6, 2016 · 3 comments
Closed

BigDecimal conversion problem - morphia 1.3 - MongoDB 3.4 #1093

jorge-tautz opened this issue Dec 6, 2016 · 3 comments
Labels
Milestone

Comments

@jorge-tautz
Copy link

Hello, i'm using MongoDB 3.4 and morphia 1.3 to test the new Decimal128 data type. I use to have a custom TypeConverter for my BigDecimals, they were stored on the database as strings.

So far i've disabled my custom converter, and updated the data directly on MongoDB. I can't make morphia save my BigDecimals as Decimal128. Inspecting the execution seems like the Mapper doesn't get the desired converter to BigDecimal, instead it uses the default Embedded Mapper.

The class for my test:

public class Main {

    public static void main(String[] args) {
        Morphia morphia = new Morphia();
        Datastore datastore = morphia.createDatastore(new MongoClient("localhost"), "bigdecimal");
        Foo foo = new Foo();
        foo.setNumber(new BigDecimal("0.92348237942346239"));
        datastore.save(foo);
    }
}

@Entity
class Foo {

    @Id
    private ObjectId id;
    private BigDecimal number;

    public ObjectId getId() {
        return id;
    }

    public void setId(ObjectId id) {
        this.id = id;
    }

    public BigDecimal getNumber() {
        return number;
    }

    public void setNumber(BigDecimal number) {
        this.number = number;
    }

}

And a database db.Foo.find():

{
        "_id" : ObjectId("5846fa9aa618770ee4f115d7"),
        "className" : "Foo",
        "number" : {
                "intVal" : {
                        "signum" : 1,
                        "mag" : [
                                21501499,
                                -1372597761
                        ],
                        "bitCount" : 0,
                        "bitLength" : 0,
                        "lowestSetBit" : 0,
                        "firstNonzeroIntNum" : 0
                },
                "scale" : 17
        }
}

Am I missing some configuration for the conversion BigDecimal <-> Decimal128 work properly?

@evanchooly evanchooly added the bug label Dec 6, 2016
@evanchooly evanchooly added this to the 1.3.1 milestone Dec 6, 2016
@evanchooly
Copy link
Member

Oh, dear. That's definitely a bug. A missing super constructor call. Turns out we tested all the conversion scenarios by invoking the converter directly and never tried round tripping that conversion in an entity. mea culpa.

@jorge-tautz
Copy link
Author

Nice! Missed that too, my custom converter had the superconstructor call.

Thanks for the quick fix, any estimate when the v1.3.1 will be available on maven?

@evanchooly
Copy link
Member

Probably next week at this point. There's a handful of minor updates I'd like to take a look at first.

evanchooly pushed a commit that referenced this issue Dec 9, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants