Skip to content

Commit

Permalink
Merge branch 'main' into example-realworldapp
Browse files Browse the repository at this point in the history
  • Loading branch information
l-trotta authored Feb 1, 2024
2 parents 06eafeb + 280f846 commit 0820b0b
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 7 deletions.
2 changes: 1 addition & 1 deletion docs/getting-started.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ include-tagged::{doc-tests-src}/usage/IndexingTest.java[single-doc-delete]

["source","java"]
--------------------------------------------------
include-tagged::{doc-tests-src}/usage/IndexingTest.java[create-products-index]
include-tagged::{doc-tests-src}/usage/IndexingTest.java[delete-products-index]
--------------------------------------------------


Expand Down
2 changes: 1 addition & 1 deletion java-client-serverless/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ dependencies {
// Needed even if using Jackson to have an implementation of the Jsonp object model
// EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
// https://github.com/eclipse-ee4j/parsson
api("org.eclipse.parsson:parsson:1.0.0")
api("org.eclipse.parsson:parsson:1.0.5")

// OpenTelemetry API for native instrumentation of the client.
// Apache 2.0
Expand Down
2 changes: 1 addition & 1 deletion java-client/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ dependencies {
// Needed even if using Jackson to have an implementation of the Jsonp object model
// EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
// https://github.com/eclipse-ee4j/parsson
api("org.eclipse.parsson:parsson:1.0.0")
api("org.eclipse.parsson:parsson:1.0.5")

// OpenTelemetry API for native instrumentation of the client.
// Apache 2.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,18 @@

package co.elastic.clients.json;

import co.elastic.clients.json.JsonpMapper;
import co.elastic.clients.json.jackson.JacksonJsonpMapper;
import co.elastic.clients.json.jsonb.JsonbJsonpMapper;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
import jakarta.json.JsonArray;
import jakarta.json.JsonNumber;
import jakarta.json.bind.spi.JsonbProvider;
import jakarta.json.stream.JsonGenerator;
import jakarta.json.stream.JsonParser;
import org.eclipse.parsson.JsonProviderImpl;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

Expand All @@ -46,16 +49,18 @@ public class JsonpMapperTest extends Assertions {

@Test
public void testJsonb() {
JsonpMapper mapper = new JsonbJsonpMapper();
JsonpMapper mapper = new JsonbJsonpMapper(new JsonProviderImpl(), JsonbProvider.provider());
testSerialize(mapper, json);
testDeserialize(mapper, json);
testLargeNumber(mapper);
}

@Test
public void testJackson() {
JacksonJsonpMapper mapper = new JacksonJsonpMapper();
testSerialize(new JacksonJsonpMapper(), json);
testDeserialize(new JacksonJsonpMapper(), json);
testSerialize(mapper, json);
testDeserialize(mapper, json);
testLargeNumber(mapper);
}

@Test
Expand Down Expand Up @@ -149,6 +154,20 @@ private void testDeserialize(JsonpMapper mapper, String json) {
assertNull(child.getChildren());
}

private void testLargeNumber(JsonpMapper mapper) {
String json = "[1e999999]";
JsonParser parser = mapper.jsonProvider().createParser(new StringReader(json));
parser.next();

JsonArray array = parser.getValue().asJsonArray();

JsonNumber number = array.getJsonNumber(0);

assertTrue(Double.isInfinite(number.doubleValue()));

Assertions.assertThrows(Exception.class, number::bigIntegerValue);
}

public static class SomeClass {
private List<SomeClass> children;
private double doubleValue;
Expand Down

0 comments on commit 0820b0b

Please sign in to comment.