-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
IGNITE-23648 Deserialize Instant objects as BigDecimals in Micronaut (#…
- Loading branch information
Showing
5 changed files
with
141 additions
and
66 deletions.
There are no files selected for viewing
66 changes: 0 additions & 66 deletions
66
modules/cli/src/main/java/org/apache/ignite/internal/cli/call/unit/UnitStatusRecord.java
This file was deleted.
Oops, something went wrong.
71 changes: 71 additions & 0 deletions
71
...es/rest-api/src/test/java/org/apache/ignite/internal/rest/InstantDeserializationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.ignite.internal.rest; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.is; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.DeserializationFeature; | ||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; | ||
import io.micronaut.context.annotation.Property; | ||
import io.micronaut.http.HttpRequest; | ||
import io.micronaut.http.client.HttpClient; | ||
import io.micronaut.http.client.annotation.Client; | ||
import io.micronaut.test.extensions.junit5.annotation.MicronautTest; | ||
import jakarta.inject.Inject; | ||
import java.time.Instant; | ||
import org.junit.jupiter.api.Test; | ||
|
||
@MicronautTest | ||
@Property(name = "micronaut.security.enabled", value = "false") | ||
@Property(name = "jackson.deserialization.use_big_decimal_for_floats", value = "true") | ||
class InstantDeserializationTest { | ||
// Specific value which will be truncated if deserialized as the double | ||
private static final Instant INSTANT = Instant.ofEpochSecond(1730977056L, 232784600); | ||
|
||
@Inject | ||
@Client("/time") | ||
HttpClient client; | ||
|
||
@Test | ||
void micronautDeserialization() { | ||
// The TestController will deserialize the instant and return a string representation. | ||
String response = client.toBlocking().retrieve(HttpRequest.POST("/", new TimeDto(INSTANT))); | ||
|
||
assertThat(response, is(INSTANT.toString())); | ||
} | ||
|
||
@Test | ||
void jacksonDeserialization() throws JsonProcessingException { | ||
ObjectMapper mapper = new ObjectMapper().enable(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS); | ||
mapper.registerModule(new JavaTimeModule()); | ||
|
||
String serializedInstant = mapper.writeValueAsString(INSTANT); | ||
assertThat(serializedInstant, is("1730977056.232784600")); | ||
|
||
JsonNode jsonNode = mapper.readTree(serializedInstant); | ||
|
||
Instant deserializedInstant = mapper.treeToValue(jsonNode, Instant.class); | ||
|
||
assertThat(deserializedInstant.getEpochSecond(), is(INSTANT.getEpochSecond())); | ||
assertThat(deserializedInstant.getNano(), is(INSTANT.getNano())); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
modules/rest-api/src/test/java/org/apache/ignite/internal/rest/TimeController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.ignite.internal.rest; | ||
|
||
import io.micronaut.http.annotation.Body; | ||
import io.micronaut.http.annotation.Controller; | ||
import io.micronaut.http.annotation.Post; | ||
|
||
@Controller("/time") | ||
class TimeController { | ||
@Post | ||
public static String time(@Body TimeDto time) { | ||
return time.time().toString(); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
modules/rest-api/src/test/java/org/apache/ignite/internal/rest/TimeDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.ignite.internal.rest; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import java.time.Instant; | ||
|
||
class TimeDto { | ||
private final Instant time; | ||
|
||
@JsonCreator | ||
TimeDto(@JsonProperty("time") Instant time) { | ||
this.time = time; | ||
} | ||
|
||
@JsonProperty("time") | ||
Instant time() { | ||
return time; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters