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
Recording of Decimal128 via Jongo #340
Comments
No answer ? |
Hello, can you provide a code snippet with the POJO your are trying to store ? |
Do you need any other information ? |
Ok so i suppose you need to configure ObjectMapper to handle Decimal128. |
Ok, thank's! Have you found anything yet ? What's the result ? |
Hello, |
Hello! Do you have some news ? |
Is there any chance of getting an answer ? |
This is not a working example but you need to create a custom serializer/deserializer: Mapper mapper = jacksonMapper()
.addSerializer(Decimal128.class, new JsonSerializer<Decimal128>() {
@Override
public void serialize(Decimal128 decimal, JsonGenerator jgen, SerializerProvider provider) throws IOException {
//write value into the generator by using for example decimal.bigDecimalValue()
jgen.writeNumber(...);
}
})
.addDeserializer(Decimal128.class, new JsonDeserializer<Decimal128>() {
@Override
public Decimal128 deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
//read value from parser and create new instance of Decimal128
return new Decimal128(...);
}
})
.build();
Jongo jongo = new Jongo(getDatabase(), mapper);
... |
Note that Decimal128 should be support natively by jongo |
Here is a working example using BigDecimal (+de/serilization into string) @Test
public void canHandleDecimal128() {
Decimal decimal = new Decimal();
decimal.total = Decimal128.parse("10");
collection.save(decimal);
Decimal result = this.collection.findOne(decimal._id).as(Decimal.class);
assertThat(result.total).isEqualTo(new Decimal128(10));
}
private static class Decimal {
ObjectId _id;
@JsonSerialize(using = Decimal128JsonSerializer.class)
@JsonDeserialize(using = Decimal128JsonDeserializer.class)
Decimal128 total;
}
private static class Decimal128JsonDeserializer extends JsonDeserializer<Decimal128> {
@Override
public Decimal128 deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
return new Decimal128(new BigDecimal(jp.getValueAsString()));
}
}
private static class Decimal128JsonSerializer extends JsonSerializer<Decimal128> {
@Override
public void serialize(Decimal128 decimal, JsonGenerator jgen, SerializerProvider provider) throws IOException {
jgen.writeString(decimal.bigDecimalValue().toString());
}
} This test has been added into test suite: https://github.com/bguerout/jongo/blob/master/src/test/java/org/jongo/spike/QuestionsSpikeTest.java#L195 |
The trouble with this is that writeNumber(BigDecimal value) transforms my value into a double value, not Decimal128 value... |
Have you checked with the second example ? |
"Note that Decimal128 should be support natively by jongo", not by jongo but by mongo, isn't it ? |
I saw your second example, but the trouble is that my Decimal128 values can't be registred like string in my database (I do statistics so I need numerical values) |
I also tried with this : |
Not sure if the following serializer can do the job private static class Decimal128JsonSerializer extends JsonSerializer<Decimal128> {
@Override
public void serialize(Decimal128 decimal, JsonGenerator jsonGenerator, SerializerProvider provider) throws IOException {
jsonGenerator.writeStartObject();
jsonGenerator.writeFieldName("$numberDecimal");
jsonGenerator.writeString(decimal.bigDecimalValue().toString());
jsonGenerator.writeEndObject();
}
}
``
I'm going to try to add Decimal128 support into Jongo |
Sorry but i can't presently release a version. I've created pull request to handle Decimal128. |
No plans to release version to support Decimal128 before 1.5.0? |
@bguerout : as @creativearmenia has said : "no plans to release version to support Decimal128 before 1.5.0?" Is it possible to build by myself an intermediate version ? |
I think i can backport this fix and release a 1.4.1 version.
…On Tue, Mar 10, 2020 at 7:35 PM JulesCizor ***@***.***> wrote:
@bguerout <https://github.com/bguerout> : as @creativearmenia
<https://github.com/creativearmenia> has said : "no plans to release
version to support Decimal128 before 1.5.0?"
Is it possible to build by myself an intermediate version ?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#340?email_source=notifications&email_token=AABWAG6FXN5BEPFRYD7FLHDRG2B53A5CNFSM4FHSR7SKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEOMUAHI#issuecomment-597245981>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AABWAG4DKWES7BE42E46KMDRG2B53ANCNFSM4FHSR7SA>
.
|
This would be very appreciable :D |
I've deployed a SNAPSHOT version. <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
...
<dependencies>
<dependency>
<groupId>org.jongo</groupId>
<artifactId>jongo</artifactId>
<version>1.4.1-SNAPSHOT</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>sonatype-snapshots</id>
<name>Sonatype Public</name>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
...
</project> |
After testing in an environnement composed of :
It works perfectly ! Conf add in play dependencies.yml
Result obtained and observed using Robo3T : |
Please let me know when version 1.4.1 will be officially delivered. |
1.4.1 has just been released <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
...
<dependencies>
<dependency>
<groupId>org.jongo</groupId>
<artifactId>jongo</artifactId>
<version>1.4.1</version>
</dependency>
</dependencies>
...
</project> |
Thank you for everything |
I'm working with Jongo 1.4, which is supposed to take into account Decimal128 type. Thus, I would like to know why, when I'm trying to register a Decimal128 in a database, it appears like an Object and not like a NumberValue ?
Do you have any solution for me to force NumberValue ?
Thank you in advance for your answer.
The text was updated successfully, but these errors were encountered: