[JAVA-26735] Upgraded gson library to 2.10.1 version
This commit is contained in:
parent
26a57c08ee
commit
0f6149ef8c
|
@ -79,7 +79,7 @@
|
|||
</build>
|
||||
|
||||
<properties>
|
||||
<gson.version>2.8.0</gson.version>
|
||||
<gson.version>2.10.1</gson.version>
|
||||
<dynamodblocal.version>1.21.1</dynamodblocal.version>
|
||||
<maven-plugins-version>3.1.1</maven-plugins-version>
|
||||
</properties>
|
||||
|
|
|
@ -73,7 +73,7 @@
|
|||
</build>
|
||||
|
||||
<properties>
|
||||
<gson.version>2.8.0</gson.version>
|
||||
<gson.version>2.10.1</gson.version>
|
||||
<dynamodblocal.version>1.21.1</dynamodblocal.version>
|
||||
<commons-codec-version>1.10.L001</commons-codec-version>
|
||||
<jets3t-version>0.9.4.0006L</jets3t-version>
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
|
||||
<properties>
|
||||
<javax.websocket-api.version>1.1</javax.websocket-api.version>
|
||||
<gson.version>2.8.0</gson.version>
|
||||
<gson.version>2.10.1</gson.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
|
@ -64,7 +64,7 @@
|
|||
</build>
|
||||
|
||||
<properties>
|
||||
<gson.version>2.8.0</gson.version>
|
||||
<gson.version>2.10.1</gson.version>
|
||||
<joda-time.version>2.9.6</joda-time.version>
|
||||
</properties>
|
||||
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
package com.baeldung.gson.conversion;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import com.google.gson.*;
|
||||
import org.junit.Assert;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class JsonObjectConversionsUnitTest {
|
||||
|
@ -10,24 +12,29 @@ public class JsonObjectConversionsUnitTest {
|
|||
void whenUsingJsonParser_thenConvertToJsonObject() throws Exception {
|
||||
// Example 1: Using JsonParser
|
||||
String json = "{ \"name\": \"Baeldung\", \"java\": true }";
|
||||
|
||||
JsonObject jsonObject = new JsonParser().parse(json).getAsJsonObject();
|
||||
|
||||
Assert.assertTrue(jsonObject.isJsonObject());
|
||||
Assert.assertTrue(jsonObject.get("name").getAsString().equals("Baeldung"));
|
||||
Assert.assertTrue(jsonObject.get("java").getAsBoolean() == true);
|
||||
|
||||
JsonObject jsonObject = JsonParser.parseString(json)
|
||||
.getAsJsonObject();
|
||||
|
||||
assertTrue(jsonObject.isJsonObject());
|
||||
assertEquals("Baeldung", jsonObject.get("name")
|
||||
.getAsString());
|
||||
assertTrue(jsonObject.get("java")
|
||||
.getAsBoolean());
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenUsingGsonInstanceFromJson_thenConvertToJsonObject() throws Exception {
|
||||
// Example 2: Using fromJson
|
||||
String json = "{ \"name\": \"Baeldung\", \"java\": true }";
|
||||
|
||||
|
||||
JsonObject convertedObject = new Gson().fromJson(json, JsonObject.class);
|
||||
|
||||
Assert.assertTrue(convertedObject.isJsonObject());
|
||||
Assert.assertTrue(convertedObject.get("name").getAsString().equals("Baeldung"));
|
||||
Assert.assertTrue(convertedObject.get("java").getAsBoolean() == true);
|
||||
|
||||
assertTrue(convertedObject.isJsonObject());
|
||||
assertEquals("Baeldung", convertedObject.get("name")
|
||||
.getAsString());
|
||||
assertTrue(convertedObject.get("java")
|
||||
.getAsBoolean());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@
|
|||
|
||||
<properties>
|
||||
<jsonb-api.version>1.0</jsonb-api.version>
|
||||
<gson.version>2.8.5</gson.version>
|
||||
<gson.version>2.10.1</gson.version>
|
||||
<javax.version>1.1.2</javax.version>
|
||||
<json-unit-assertj.version>2.28.0</json-unit-assertj.version>
|
||||
</properties>
|
||||
|
|
|
@ -68,7 +68,7 @@
|
|||
<networknt.json.schema.version>1.0.72</networknt.json.schema.version>
|
||||
<jsonb-api.version>1.0</jsonb-api.version>
|
||||
<yasson.version>1.0.1</yasson.version>
|
||||
<gson.version>2.8.5</gson.version>
|
||||
<gson.version>2.10.1</gson.version>
|
||||
<javax.version>1.1.2</javax.version>
|
||||
<json-unit-assertj.version>2.28.0</json-unit-assertj.version>
|
||||
</properties>
|
||||
|
|
|
@ -106,7 +106,7 @@
|
|||
<google-sheets.version>v4-rev493-1.21.0</google-sheets.version>
|
||||
<docx4j.version>6.1.2</docx4j.version>
|
||||
<jaxb-runtime.version>2.3.1</jaxb-runtime.version>
|
||||
<gson.version>2.8.7</gson.version>
|
||||
<gson.version>2.10.1</gson.version>
|
||||
<yamlbeans.version>1.15</yamlbeans.version>
|
||||
<apache-thrift.version>0.14.2</apache-thrift.version>
|
||||
<google-protobuf.version>3.17.3</google-protobuf.version>
|
||||
|
|
|
@ -210,7 +210,7 @@
|
|||
<kafka.version>3.3.1</kafka.version>
|
||||
<ignite.version>2.14.0</ignite.version>
|
||||
<ignite-spring-data.version>2.9.1</ignite-spring-data.version>
|
||||
<gson.version>2.9.1</gson.version>
|
||||
<gson.version>2.10.1</gson.version>
|
||||
<cache.version>1.1.1</cache.version>
|
||||
<flink.version>1.5.0</flink.version>
|
||||
<hazelcast.version>5.2.0</hazelcast.version>
|
||||
|
|
|
@ -110,7 +110,7 @@
|
|||
|
||||
<properties>
|
||||
<okhttp.version>4.9.1</okhttp.version>
|
||||
<gson.version>2.8.5</gson.version>
|
||||
<gson.version>2.10.1</gson.version>
|
||||
<mockwebserver.version>4.9.1</mockwebserver.version>
|
||||
<jetty.httpclient.version>1.0.3</jetty.httpclient.version>
|
||||
<jetty.server.version>9.4.19.v20190610</jetty.server.version>
|
||||
|
|
|
@ -103,7 +103,7 @@
|
|||
</dependencies>
|
||||
|
||||
<properties>
|
||||
<gson.version>2.8.5</gson.version>
|
||||
<gson.version>2.10.1</gson.version>
|
||||
<httpclient.version>4.5.3</httpclient.version>
|
||||
<com.squareup.okhttp3.version>4.9.1</com.squareup.okhttp3.version>
|
||||
<googleclient.version>1.23.0</googleclient.version>
|
||||
|
|
|
@ -49,7 +49,7 @@
|
|||
|
||||
<properties>
|
||||
<org.apache.httpcomponents.version>4.5.3</org.apache.httpcomponents.version>
|
||||
<gson.version>2.8.2</gson.version>
|
||||
<gson.version>2.10.1</gson.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
|
@ -30,7 +30,7 @@
|
|||
|
||||
<properties>
|
||||
<sparkjava.spark-core.version>2.5.4</sparkjava.spark-core.version>
|
||||
<google.code.gson.version>2.8.0</google.code.gson.version>
|
||||
<google.code.gson.version>2.10.1</google.code.gson.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
Loading…
Reference in New Issue