Fix build
ci/woodpecker/push/woodpecker Pipeline was successful Details

This commit is contained in:
Johannes Frohnmeyer 2023-09-19 20:14:48 +02:00
parent c46cbf85d4
commit 7d030fad60
Signed by: Johannes
GPG Key ID: E76429612C2929F4
45 changed files with 181 additions and 422 deletions

View File

@ -1,31 +0,0 @@
<!--
Thank you for your contribution!
Please see the contributing guide: https://github.com/google/.github/blob/master/CONTRIBUTING.md
Keep in mind that Gson is in maintenance mode. If you want to add a new feature, please first search for existing GitHub issues, or create a new one to discuss the feature and get feedback.
-->
### Purpose
<!-- Describe the purpose of this pull request, for example which new feature it adds or which bug it fixes -->
<!-- If this pull request closes a GitHub issue, please write "Closes #<issue>", for example "Closes #123" -->
### Description
<!-- If necessary provide more information, for example relevant implementation details or corner cases which are not covered yet -->
<!-- If there are related issues or pull requests, link to them by referencing their number, for example "pull request #123" -->
### Checklist
<!-- The following checklist is mainly intended for yourself to verify that you did not miss anything -->
- [ ] New code follows the [Google Java Style Guide](https://google.github.io/styleguide/javaguide.html)
- [ ] If necessary, new public API validates arguments, for example rejects `null`
- [ ] New public API has Javadoc
- [ ] Javadoc uses `@since $next-version$`
(`$next-version$` is a special placeholder which is automatically replaced during release)
- [ ] If necessary, new unit tests have been added
- [ ] Assertions in unit tests use [Truth](https://truth.dev/), see existing tests
- [ ] No JUnit 3 features are used (such as extending class `TestCase`)
- [ ] If this pull request fixes a bug, a new test was added for a situation which failed previously and is now fixed
- [ ] `mvn clean verify javadoc:jar` passes without errors

View File

@ -1,29 +0,0 @@
# For security reasons this is a separate GitHub workflow, see https://github.com/google/gson/issues/2429#issuecomment-1622522842
# Once https://github.com/mojohaus/animal-sniffer/issues/252 or https://github.com/mojohaus/animal-sniffer/pull/253
# are resolved, can consider adjusting pom.xml to include this as part of normal Maven build
name: Check Android compatibility
on: [push, pull_request]
permissions:
contents: read # to fetch code (actions/checkout)
jobs:
check-android-compatibility:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '11'
cache: 'maven'
- name: Check Android compatibility
run: |
# Run 'test' phase because plugin normally expects to be executed after tests have been compiled
mvn --batch-mode --no-transfer-progress test animal-sniffer:check@check-android-compatibility -DskipTests

View File

@ -20,7 +20,7 @@
<parent>
<groupId>io.gitlab.jfronny</groupId>
<artifactId>gson-parent</artifactId>
<version>2.10.2-SNAPSHOT</version>
<version>2.10.3-SNAPSHOT</version>
</parent>
<artifactId>gson</artifactId>
@ -34,16 +34,12 @@
</licenses>
<dependencies>
<!-- This dependency can be considered optional; omitting it during runtime will most likely
not cause any issues. However, it is not declared with `<optional>true</optional>` because
that can lead to cryptic compiler warnings for consumers, and to be on the safe side in case
there are actually issues which could occur when the dependency is missing at runtime.
See also discussion at https://github.com/google/gson/pull/2320#issuecomment-1455233938 -->
<dependency>
<groupId>com.google.errorprone</groupId>
<artifactId>error_prone_annotations</artifactId>
<version>2.21.1</version>
</dependency>
<!--
errorprone was removed due to JPMS:
It complained that the module didn't exist when included in module-info.java,
otherwise it complained about it existing but not being referenced.
In other words, it just didn't work.
-->
<dependency>
<groupId>junit</groupId>
@ -193,7 +189,7 @@
<plugin>
<groupId>org.moditect</groupId>
<artifactId>moditect-maven-plugin</artifactId>
<version>1.0.0.Final</version>
<version>1.0.0.RC2</version>
<executions>
<execution>
<id>add-module-info</id>

View File

@ -18,6 +18,7 @@ package com.google.gson;
import com.google.gson.annotations.JsonAdapter;
import com.google.gson.internal.ConstructorConstructor;
import com.google.gson.internal.DefaultConfig;
import com.google.gson.internal.Excluder;
import com.google.gson.internal.GsonBuildConfig;
import com.google.gson.internal.LazilyParsedNumber;
@ -235,7 +236,7 @@ public final class Gson {
this(Excluder.DEFAULT, DefaultConfig.DEFAULT_FIELD_NAMING_STRATEGY,
Collections.<Type, InstanceCreator<?>>emptyMap(), DefaultConfig.DEFAULT_SERIALIZE_NULLS,
DefaultConfig.DEFAULT_COMPLEX_MAP_KEYS, DefaultConfig.DEFAULT_DUPLICATE_MAP_KEYS, DefaultConfig.DEFAULT_JSON_NON_EXECUTABLE, DefaultConfig.DEFAULT_ESCAPE_HTML,
DefaultConfig.DEFAULT_FORMATTING_STYLE, DefaultConfig.DEFAULT_STRICTNESS, DefaultConfig.DEFAULT_OMIT_QUOTES, DefaultConfig.DEFAULT_SPECIALIZE_FLOAT_VALUES,
DefaultConfig.DEFAULT_FORMATTING_STYLE, Strictness.LENIENT, DefaultConfig.DEFAULT_OMIT_QUOTES, DefaultConfig.DEFAULT_SPECIALIZE_FLOAT_VALUES,
DefaultConfig.DEFAULT_USE_JDK_UNSAFE,
LongSerializationPolicy.DEFAULT, DefaultConfig.DEFAULT_DATE_PATTERN, DateFormat.DEFAULT, DateFormat.DEFAULT,
Collections.<TypeAdapterFactory>emptyList(), Collections.<TypeAdapterFactory>emptyList(),

View File

@ -18,8 +18,6 @@ package com.google.gson;
import static com.google.gson.internal.DefaultConfig.*;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.errorprone.annotations.InlineMe;
import com.google.gson.annotations.Since;
import com.google.gson.annotations.Until;
import com.google.gson.internal.$Gson$Preconditions;
@ -158,7 +156,6 @@ public final class GsonBuilder {
* @see Since
* @see Until
*/
@CanIgnoreReturnValue
public GsonBuilder setVersion(double version) {
if (Double.isNaN(version) || version < 0.0) {
throw new IllegalArgumentException("Invalid version: " + version);
@ -181,7 +178,6 @@ public final class GsonBuilder {
* {@link java.lang.reflect.Modifier#STATIC}.
* @return a reference to this {@code GsonBuilder} object to fulfill the "Builder" pattern
*/
@CanIgnoreReturnValue
public GsonBuilder excludeFieldsWithModifiers(int... modifiers) {
Objects.requireNonNull(modifiers);
excluder = excluder.withModifiers(modifiers);
@ -197,7 +193,6 @@ public final class GsonBuilder {
* @return a reference to this {@code GsonBuilder} object to fulfill the "Builder" pattern
* @since 1.3
*/
@CanIgnoreReturnValue
public GsonBuilder generateNonExecutableJson() {
this.generateNonExecutableJson = true;
return this;
@ -212,7 +207,6 @@ public final class GsonBuilder {
*
* @return a reference to this {@code GsonBuilder} object to fulfill the "Builder" pattern
*/
@CanIgnoreReturnValue
public GsonBuilder excludeFieldsWithoutExposeAnnotation() {
excluder = excluder.excludeFieldsWithoutExposeAnnotation();
return this;
@ -225,7 +219,6 @@ public final class GsonBuilder {
* @return a reference to this {@code GsonBuilder} object to fulfill the "Builder" pattern
* @since 1.2
*/
@CanIgnoreReturnValue
public GsonBuilder serializeNulls() {
this.serializeNulls = true;
return this;
@ -310,7 +303,6 @@ public final class GsonBuilder {
* @return a reference to this {@code GsonBuilder} object to fulfill the "Builder" pattern
* @since 1.7
*/
@CanIgnoreReturnValue
public GsonBuilder enableComplexMapKeySerialization() {
complexMapKeySerialization = true;
return this;
@ -351,7 +343,6 @@ public final class GsonBuilder {
* @return a reference to this {@code GsonBuilder} object to fulfill the "Builder" pattern
* @since 1.3
*/
@CanIgnoreReturnValue
public GsonBuilder disableInnerClassSerialization() {
excluder = excluder.disableInnerClassSerialization();
return this;
@ -365,7 +356,6 @@ public final class GsonBuilder {
* @return a reference to this {@code GsonBuilder} object to fulfill the "Builder" pattern
* @since 1.3
*/
@CanIgnoreReturnValue
public GsonBuilder setLongSerializationPolicy(LongSerializationPolicy serializationPolicy) {
this.longSerializationPolicy = Objects.requireNonNull(serializationPolicy);
return this;
@ -377,7 +367,6 @@ public final class GsonBuilder {
*
* <p>This method just delegates to {@link #setFieldNamingStrategy(FieldNamingStrategy)}.
*/
@CanIgnoreReturnValue
public GsonBuilder setFieldNamingPolicy(FieldNamingPolicy namingConvention) {
return setFieldNamingStrategy(namingConvention);
}
@ -394,7 +383,6 @@ public final class GsonBuilder {
* @return a reference to this {@code GsonBuilder} object to fulfill the "Builder" pattern
* @since 1.3
*/
@CanIgnoreReturnValue
public GsonBuilder setFieldNamingStrategy(FieldNamingStrategy fieldNamingStrategy) {
this.fieldNamingPolicy = Objects.requireNonNull(fieldNamingStrategy);
return this;
@ -408,7 +396,6 @@ public final class GsonBuilder {
* @see ToNumberPolicy#DOUBLE The default object-to-number strategy
* @since 2.8.9
*/
@CanIgnoreReturnValue
public GsonBuilder setObjectToNumberStrategy(ToNumberStrategy objectToNumberStrategy) {
this.objectToNumberStrategy = Objects.requireNonNull(objectToNumberStrategy);
return this;
@ -422,7 +409,6 @@ public final class GsonBuilder {
* @see ToNumberPolicy#LAZILY_PARSED_NUMBER The default number-to-number strategy
* @since 2.8.9
*/
@CanIgnoreReturnValue
public GsonBuilder setNumberToNumberStrategy(ToNumberStrategy numberToNumberStrategy) {
this.numberToNumberStrategy = Objects.requireNonNull(numberToNumberStrategy);
return this;
@ -454,7 +440,6 @@ public final class GsonBuilder {
* @return a reference to this {@code GsonBuilder} object to fulfill the "Builder" pattern
* @since 1.4
*/
@CanIgnoreReturnValue
public GsonBuilder setExclusionStrategies(ExclusionStrategy... strategies) {
Objects.requireNonNull(strategies);
for (ExclusionStrategy strategy : strategies) {
@ -478,7 +463,6 @@ public final class GsonBuilder {
* @return a reference to this {@code GsonBuilder} object to fulfill the "Builder" pattern
* @since 1.7
*/
@CanIgnoreReturnValue
public GsonBuilder addSerializationExclusionStrategy(ExclusionStrategy strategy) {
Objects.requireNonNull(strategy);
excluder = excluder.withExclusionStrategy(strategy, true, false);
@ -500,7 +484,6 @@ public final class GsonBuilder {
* @return a reference to this {@code GsonBuilder} object to fulfill the "Builder" pattern
* @since 1.7
*/
@CanIgnoreReturnValue
public GsonBuilder addDeserializationExclusionStrategy(ExclusionStrategy strategy) {
Objects.requireNonNull(strategy);
excluder = excluder.withExclusionStrategy(strategy, false, true);
@ -516,7 +499,6 @@ public final class GsonBuilder {
*
* @return a reference to this {@code GsonBuilder} object to fulfill the "Builder" pattern
*/
@CanIgnoreReturnValue
public GsonBuilder setPrettyPrinting() {
return setFormattingStyle(FormattingStyle.PRETTY);
}
@ -529,7 +511,6 @@ public final class GsonBuilder {
* @return a reference to this {@code GsonBuilder} object to fulfill the "Builder" pattern
* @since $next-version$
*/
@CanIgnoreReturnValue
public GsonBuilder setFormattingStyle(FormattingStyle formattingStyle) {
this.formattingStyle = Objects.requireNonNull(formattingStyle);
return this;
@ -547,8 +528,6 @@ public final class GsonBuilder {
* @see #setStrictness(Strictness)
*/
@Deprecated
@InlineMe(replacement = "this.setStrictness(Strictness.LENIENT)", imports = "com.google.gson.Strictness")
@CanIgnoreReturnValue
public GsonBuilder setLenient() {
return setStrictness(Strictness.LENIENT);
}
@ -567,7 +546,6 @@ public final class GsonBuilder {
* @see JsonWriter#setStrictness(Strictness)
* @since $next-version$
*/
@CanIgnoreReturnValue
public GsonBuilder setStrictness(Strictness strictness) {
this.strictness = Objects.requireNonNull(strictness);
return this;
@ -589,7 +567,6 @@ public final class GsonBuilder {
* @return a reference to this {@code GsonBuilder} object to fulfill the "Builder" pattern
* @since 1.3
*/
@CanIgnoreReturnValue
public GsonBuilder disableHtmlEscaping() {
this.escapeHtmlChars = false;
return this;
@ -611,7 +588,6 @@ public final class GsonBuilder {
* @return a reference to this {@code GsonBuilder} object to fulfill the "Builder" pattern
* @since 1.2
*/
@CanIgnoreReturnValue
public GsonBuilder setDateFormat(String pattern) {
// TODO(Joel): Make this fail fast if it is an invalid date format
this.datePattern = pattern;
@ -632,7 +608,6 @@ public final class GsonBuilder {
* @return a reference to this {@code GsonBuilder} object to fulfill the "Builder" pattern
* @since 1.2
*/
@CanIgnoreReturnValue
public GsonBuilder setDateFormat(int style) {
this.dateStyle = style;
this.datePattern = null;
@ -654,7 +629,6 @@ public final class GsonBuilder {
* @return a reference to this {@code GsonBuilder} object to fulfill the "Builder" pattern
* @since 1.2
*/
@CanIgnoreReturnValue
public GsonBuilder setDateFormat(int dateStyle, int timeStyle) {
this.dateStyle = dateStyle;
this.timeStyle = timeStyle;
@ -684,7 +658,6 @@ public final class GsonBuilder {
* {@link InstanceCreator}, {@link JsonSerializer}, and a {@link JsonDeserializer} interfaces.
* @return a reference to this {@code GsonBuilder} object to fulfill the "Builder" pattern
*/
@CanIgnoreReturnValue
public GsonBuilder registerTypeAdapter(Type type, Object typeAdapter) {
Objects.requireNonNull(type);
$Gson$Preconditions.checkArgument(typeAdapter instanceof JsonSerializer<?>
@ -718,7 +691,6 @@ public final class GsonBuilder {
*
* @since 2.1
*/
@CanIgnoreReturnValue
public GsonBuilder registerTypeAdapterFactory(TypeAdapterFactory factory) {
Objects.requireNonNull(factory);
factories.add(factory);
@ -739,7 +711,6 @@ public final class GsonBuilder {
* @return a reference to this {@code GsonBuilder} object to fulfill the "Builder" pattern
* @since 1.7
*/
@CanIgnoreReturnValue
public GsonBuilder registerTypeHierarchyAdapter(Class<?> baseType, Object typeAdapter) {
Objects.requireNonNull(baseType);
$Gson$Preconditions.checkArgument(typeAdapter instanceof JsonSerializer<?>
@ -776,7 +747,6 @@ public final class GsonBuilder {
* @return a reference to this {@code GsonBuilder} object to fulfill the "Builder" pattern
* @since 1.3
*/
@CanIgnoreReturnValue
public GsonBuilder serializeSpecialFloatingPointValues() {
this.serializeSpecialFloatingPointValues = true;
return this;
@ -798,7 +768,6 @@ public final class GsonBuilder {
* @return a reference to this {@code GsonBuilder} object to fulfill the "Builder" pattern
* @since 2.9.0
*/
@CanIgnoreReturnValue
public GsonBuilder disableJdkUnsafe() {
this.useJdkUnsafe = false;
return this;
@ -824,7 +793,6 @@ public final class GsonBuilder {
* @return a reference to this {@code GsonBuilder} object to fulfill the "Builder" pattern
* @since 2.9.1
*/
@CanIgnoreReturnValue
public GsonBuilder addReflectionAccessFilter(ReflectionAccessFilter filter) {
Objects.requireNonNull(filter);
reflectionFilters.addFirst(filter);

View File

@ -16,7 +16,6 @@
package com.google.gson;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.gson.internal.NonNullElementWrapperList;
import java.math.BigDecimal;
import java.math.BigInteger;
@ -146,7 +145,6 @@ public final class JsonArray extends JsonElement implements Iterable<JsonElement
* @return the element previously at the specified position
* @throws IndexOutOfBoundsException if the specified index is outside the array bounds
*/
@CanIgnoreReturnValue
public JsonElement set(int index, JsonElement element) {
return elements.set(index, element == null ? JsonNull.INSTANCE : element);
}
@ -159,7 +157,6 @@ public final class JsonArray extends JsonElement implements Iterable<JsonElement
* @return true if this array contained the specified element, false otherwise
* @since 2.3
*/
@CanIgnoreReturnValue
public boolean remove(JsonElement element) {
return elements.remove(element);
}
@ -174,7 +171,6 @@ public final class JsonArray extends JsonElement implements Iterable<JsonElement
* @throws IndexOutOfBoundsException if the specified index is outside the array bounds
* @since 2.3
*/
@CanIgnoreReturnValue
public JsonElement remove(int index) {
return elements.remove(index);
}

View File

@ -16,7 +16,6 @@
package com.google.gson;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.gson.internal.Streams;
import com.google.gson.stream.JsonWriter;
import java.io.IOException;
@ -144,7 +143,6 @@ public abstract class JsonElement {
* @throws IllegalStateException if this element is of another type.
* @since 1.2
*/
@CanIgnoreReturnValue // When this method is used only to verify that the value is JsonNull
public JsonNull getAsJsonNull() {
if (isJsonNull()) {
return (JsonNull) this;

View File

@ -16,7 +16,6 @@
package com.google.gson;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.gson.internal.LinkedTreeMap;
import java.util.Map;
import java.util.Set;
@ -78,7 +77,6 @@ public final class JsonObject extends JsonElement {
* member with this name exists.
* @since 1.3
*/
@CanIgnoreReturnValue
public JsonElement remove(String property) {
return members.remove(property);
}

View File

@ -15,7 +15,6 @@
*/
package com.google.gson;
import com.google.errorprone.annotations.InlineMe;
import com.google.gson.internal.Streams;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonToken;
@ -112,21 +111,18 @@ public final class JsonParser {
/** @deprecated Use {@link JsonParser#parseString} */
@Deprecated
@InlineMe(replacement = "JsonParser.parseString(json)", imports = "com.google.gson.JsonParser")
public JsonElement parse(String json) throws JsonSyntaxException {
return parseString(json);
}
/** @deprecated Use {@link JsonParser#parseReader(Reader)} */
@Deprecated
@InlineMe(replacement = "JsonParser.parseReader(json)", imports = "com.google.gson.JsonParser")
public JsonElement parse(Reader json) throws JsonIOException, JsonSyntaxException {
return parseReader(json);
}
/** @deprecated Use {@link JsonParser#parseReader(JsonReader)} */
@Deprecated
@InlineMe(replacement = "JsonParser.parseReader(json)", imports = "com.google.gson.JsonParser")
public JsonElement parse(JsonReader json) throws JsonIOException, JsonSyntaxException {
return parseReader(json);
}

View File

@ -5,9 +5,9 @@ import com.google.gson.reflect.*;
public class DefaultConfig {
public static final boolean DEFAULT_JSON_NON_EXECUTABLE = false;
public static final boolean DEFAULT_LENIENT = false;
public static final Strictness DEFAULT_STRICTNESS = Strictness.LEGACY_STRICT;
public static final boolean DEFAULT_OMIT_QUOTES = false;
public static final FormattingStyle DEFAULT_FORMATTING_STYLE = null;
public static final FormattingStyle DEFAULT_FORMATTING_STYLE = FormattingStyle.COMPACT;
public static final boolean DEFAULT_ESCAPE_HTML = true;
public static final boolean DEFAULT_SERIALIZE_NULLS = false;
public static final boolean DEFAULT_COMPLEX_MAP_KEYS = false;

View File

@ -17,7 +17,6 @@
package com.google.gson.internal;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import java.io.IOException;
import java.io.InvalidObjectException;
import java.io.ObjectInputStream;
@ -108,7 +107,6 @@ public final class LinkedTreeMap<K, V> extends AbstractMap<K, V> implements Seri
return findByObject(key) != null;
}
@CanIgnoreReturnValue
@Override public V put(K key, V value) {
if (key == null) {
throw new NullPointerException("key == null");

View File

@ -17,6 +17,7 @@
package com.google.gson.internal.bind;
import com.google.gson.Gson;
import com.google.gson.Strictness;
import com.google.gson.TypeAdapter;
import com.google.gson.TypeAdapterFactory;
import com.google.gson.internal.$Gson$Types;
@ -65,7 +66,7 @@ public final class ArrayTypeAdapter<E> extends TypeAdapter<Object> {
in.nextNull();
return null;
}
if (in.isLenient() && in.peek() != JsonToken.BEGIN_ARRAY) {
if (in.getStrictness() == Strictness.LENIENT && in.peek() != JsonToken.BEGIN_ARRAY) {
// Coerce
Object array = Array.newInstance(componentType, 1);
Array.set(array, 0, componentTypeAdapter.read(in));

View File

@ -17,6 +17,7 @@
package com.google.gson.internal.bind;
import com.google.gson.Gson;
import com.google.gson.Strictness;
import com.google.gson.TypeAdapter;
import com.google.gson.TypeAdapterFactory;
import com.google.gson.internal.$Gson$Types;
@ -77,7 +78,7 @@ public final class CollectionTypeAdapterFactory implements TypeAdapterFactory {
}
Collection<E> collection = constructor.construct();
if (!in.isLenient() || in.peek() == JsonToken.BEGIN_ARRAY) {
if (in.getStrictness() != Strictness.LENIENT || in.peek() == JsonToken.BEGIN_ARRAY) {
in.beginArray();
while (in.hasNext()) {
E instance = elementTypeAdapter.read(in);

View File

@ -524,12 +524,8 @@ public final class TypeAdapters {
public static final TypeAdapter<URL> URL = new TypeAdapter<URL>() {
@Override
public URL read(JsonReader in) throws IOException {
if (in.peek() == JsonToken.NULL) {
in.nextNull();
return null;
}
String nextString = in.nextString();
return "null".equals(nextString) ? null : new URL(nextString);
URI uri = URI.read(in);
return uri == null ? null : uri.toURL();
}
@Override
public void write(JsonWriter out, URL value) throws IOException {

View File

@ -19,9 +19,9 @@ package com.google.gson.stream;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.Strictness;
import com.google.gson.internal.DefaultConfig;
import com.google.gson.internal.JsonReaderInternalAccess;
import com.google.gson.internal.TroubleshootingGuide;
import com.google.gson.internal.bind.JsonTreeReader;
import java.io.Closeable;
import java.io.EOFException;
import java.io.IOException;
@ -391,6 +391,7 @@ public class JsonReader implements Closeable {
public final void setStrictness(Strictness strictness) {
Objects.requireNonNull(strictness);
this.strictness = strictness;
if (strictness == Strictness.LENIENT) setSerializeSpecialFloatingPointValues(true);
}
/**

View File

@ -16,7 +16,6 @@
package com.google.gson.stream;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonNull;
@ -154,7 +153,6 @@ public final class JsonTreeReader extends JsonReader {
return stack[stackSize - 1];
}
@CanIgnoreReturnValue
private Object popStack() {
Object result = stack[--stackSize];
stack[stackSize] = null;

View File

@ -16,7 +16,6 @@
package com.google.gson.stream;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonNull;
@ -98,7 +97,6 @@ public final class JsonTreeWriter extends JsonWriter {
}
}
@CanIgnoreReturnValue
@Override public JsonWriter beginArray() throws IOException {
JsonArray array = new JsonArray();
put(array);
@ -106,7 +104,6 @@ public final class JsonTreeWriter extends JsonWriter {
return this;
}
@CanIgnoreReturnValue
@Override public JsonWriter endArray() throws IOException {
if (stack.isEmpty() || pendingName != null) {
throw new IllegalStateException();
@ -119,7 +116,6 @@ public final class JsonTreeWriter extends JsonWriter {
throw new IllegalStateException();
}
@CanIgnoreReturnValue
@Override public JsonWriter beginObject() throws IOException {
JsonObject object = new JsonObject();
put(object);
@ -127,7 +123,6 @@ public final class JsonTreeWriter extends JsonWriter {
return this;
}
@CanIgnoreReturnValue
@Override public JsonWriter endObject() throws IOException {
if (stack.isEmpty() || pendingName != null) {
throw new IllegalStateException();
@ -140,7 +135,6 @@ public final class JsonTreeWriter extends JsonWriter {
throw new IllegalStateException();
}
@CanIgnoreReturnValue
@Override public JsonWriter name(String name) throws IOException {
Objects.requireNonNull(name, "name == null");
if (stack.isEmpty() || pendingName != null) {
@ -154,7 +148,6 @@ public final class JsonTreeWriter extends JsonWriter {
throw new IllegalStateException("Please begin an object before writing a name.");
}
@CanIgnoreReturnValue
@Override public JsonWriter value(String value) throws IOException {
if (value == null) {
return nullValue();
@ -167,19 +160,16 @@ public final class JsonTreeWriter extends JsonWriter {
throw new UnsupportedOperationException();
}
@CanIgnoreReturnValue
@Override public JsonWriter nullValue() throws IOException {
put(JsonNull.INSTANCE);
return this;
}
@CanIgnoreReturnValue
@Override public JsonWriter value(boolean value) throws IOException {
put(new JsonPrimitive(value));
return this;
}
@CanIgnoreReturnValue
@Override public JsonWriter value(Boolean value) throws IOException {
if (value == null) {
return nullValue();
@ -188,7 +178,6 @@ public final class JsonTreeWriter extends JsonWriter {
return this;
}
@CanIgnoreReturnValue
@Override public JsonWriter value(float value) throws IOException {
if (!isLenient() && (Float.isNaN(value) || Float.isInfinite(value))) {
throw new IllegalArgumentException("JSON forbids NaN and infinities: " + value);
@ -197,7 +186,6 @@ public final class JsonTreeWriter extends JsonWriter {
return this;
}
@CanIgnoreReturnValue
@Override public JsonWriter value(double value) throws IOException {
if (!isLenient() && (Double.isNaN(value) || Double.isInfinite(value))) {
throw new IllegalArgumentException("JSON forbids NaN and infinities: " + value);
@ -206,13 +194,11 @@ public final class JsonTreeWriter extends JsonWriter {
return this;
}
@CanIgnoreReturnValue
@Override public JsonWriter value(long value) throws IOException {
put(new JsonPrimitive(value));
return this;
}
@CanIgnoreReturnValue
@Override public JsonWriter value(Number value) throws IOException {
if (value == null) {
return nullValue();

View File

@ -26,7 +26,6 @@ import static com.google.gson.stream.JsonScope.NONEMPTY_OBJECT;
import com.google.gson.internal.*;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.gson.FormattingStyle;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
@ -415,7 +414,6 @@ public class JsonWriter implements Closeable, Flushable {
*
* @return this writer.
*/
@CanIgnoreReturnValue
public JsonWriter beginArray() throws IOException {
writeDeferredName();
return open(EMPTY_ARRAY, '[');
@ -426,7 +424,6 @@ public class JsonWriter implements Closeable, Flushable {
*
* @return this writer.
*/
@CanIgnoreReturnValue
public JsonWriter endArray() throws IOException {
return close(EMPTY_ARRAY, NONEMPTY_ARRAY, ']');
}
@ -437,7 +434,6 @@ public class JsonWriter implements Closeable, Flushable {
*
* @return this writer.
*/
@CanIgnoreReturnValue
public JsonWriter beginObject() throws IOException {
writeDeferredName();
return open(EMPTY_OBJECT, '{');
@ -448,7 +444,6 @@ public class JsonWriter implements Closeable, Flushable {
*
* @return this writer.
*/
@CanIgnoreReturnValue
public JsonWriter endObject() throws IOException {
return close(EMPTY_OBJECT, NONEMPTY_OBJECT, '}');
}
@ -457,7 +452,6 @@ public class JsonWriter implements Closeable, Flushable {
* Enters a new scope by appending any necessary whitespace and the given
* bracket.
*/
@CanIgnoreReturnValue
private JsonWriter open(int empty, char openBracket) throws IOException {
beforeValue();
push(empty);
@ -469,7 +463,6 @@ public class JsonWriter implements Closeable, Flushable {
* Closes the current scope by appending any necessary whitespace and the
* given bracket.
*/
@CanIgnoreReturnValue
private JsonWriter close(int empty, int nonempty, char closeBracket)
throws IOException {
int context = peek();
@ -524,7 +517,7 @@ public class JsonWriter implements Closeable, Flushable {
* This writer MUST be lenient to use this
*/
public JsonWriter comment(String comment) throws IOException {
if (!lenient) throw new MalformedJsonException("Cannot write comment in non-lenient JsonWriter.");
if (strictness != Strictness.LENIENT) throw new MalformedJsonException("Cannot write comment in non-lenient JsonWriter.");
if (comment == null || comment.isBlank()) return this;
String[] parts = comment.split("\n");
Collections.addAll(deferredComment, parts);
@ -557,7 +550,6 @@ public class JsonWriter implements Closeable, Flushable {
* @param name the name of the forthcoming value. May not be {@code null}.
* @return this writer.
*/
@CanIgnoreReturnValue
public JsonWriter name(String name) throws IOException {
Objects.requireNonNull(name, "name == null");
if (deferredName != null) {
@ -590,7 +582,6 @@ public class JsonWriter implements Closeable, Flushable {
* @param value the literal string value, or null to encode a null literal.
* @return this writer.
*/
@CanIgnoreReturnValue
public JsonWriter value(String value) throws IOException {
if (value == null) {
return nullValue();
@ -612,7 +603,6 @@ public class JsonWriter implements Closeable, Flushable {
* writing raw JSON values.
* @since 2.4
*/
@CanIgnoreReturnValue
public JsonWriter jsonValue(String value) throws IOException {
if (value == null) {
return nullValue();
@ -628,7 +618,6 @@ public class JsonWriter implements Closeable, Flushable {
*
* @return this writer.
*/
@CanIgnoreReturnValue
public JsonWriter nullValue() throws IOException {
if (deferredName != null) {
if (serializeNulls) {
@ -648,7 +637,6 @@ public class JsonWriter implements Closeable, Flushable {
*
* @return this writer.
*/
@CanIgnoreReturnValue
public JsonWriter value(boolean value) throws IOException {
writeDeferredName();
beforeValue();
@ -662,7 +650,6 @@ public class JsonWriter implements Closeable, Flushable {
* @return this writer.
* @since 2.7
*/
@CanIgnoreReturnValue
public JsonWriter value(Boolean value) throws IOException {
if (value == null) {
return nullValue();
@ -684,7 +671,6 @@ public class JsonWriter implements Closeable, Flushable {
* #setStrictness(Strictness) lenient}.
* @since 2.9.1
*/
@CanIgnoreReturnValue
public JsonWriter value(float value) throws IOException {
writeDeferredName();
if (!serializeSpecialFloatingPointValues && (Float.isNaN(value) || Float.isInfinite(value))) {
@ -704,7 +690,6 @@ public class JsonWriter implements Closeable, Flushable {
* @throws IllegalArgumentException if the value is NaN or Infinity and this writer is
* not {@link #setStrictness(Strictness) lenient}.
*/
@CanIgnoreReturnValue
public JsonWriter value(double value) throws IOException {
writeDeferredName();
if (!serializeSpecialFloatingPointValues && (Double.isNaN(value) || Double.isInfinite(value))) {
@ -720,7 +705,6 @@ public class JsonWriter implements Closeable, Flushable {
*
* @return this writer.
*/
@CanIgnoreReturnValue
public JsonWriter value(long value) throws IOException {
writeDeferredName();
beforeValue();
@ -750,7 +734,6 @@ public class JsonWriter implements Closeable, Flushable {
* not {@link #setStrictness(Strictness) lenient}; or if the {@code toString()} result is not a
* valid JSON number.
*/
@CanIgnoreReturnValue
public JsonWriter value(Number value) throws IOException {
if (value == null) {
return nullValue();

View File

@ -25,9 +25,6 @@ module io.gitlab.jfronny.gson {
exports io.gitlab.jfronny.gson.stream;
exports io.gitlab.jfronny.gson.util;
// Dependency on Error Prone Annotations
requires static com.google.errorprone.annotations;
// Optional dependency on java.sql
requires static java.sql;

View File

@ -61,13 +61,13 @@ public final class GsonTest {
@Test
public void testStrictnessDefault() {
assertThat(new Gson().strictness).isNull();
assertThat(new Gson().strictness).isEqualTo(Strictness.LENIENT);
}
@Test
public void testOverridesDefaultExcluder() {
Gson gson = new Gson(CUSTOM_EXCLUDER, CUSTOM_FIELD_NAMING_STRATEGY,
new HashMap<Type, InstanceCreator<?>>(), true, false, true, false,
new HashMap<Type, InstanceCreator<?>>(), true, false, true, false, false,
FormattingStyle.PRETTY, Strictness.LENIENT, false, false, true,
LongSerializationPolicy.DEFAULT, null, DateFormat.DEFAULT,
DateFormat.DEFAULT, new ArrayList<TypeAdapterFactory>(),
@ -84,7 +84,7 @@ public final class GsonTest {
@Test
public void testClonedTypeAdapterFactoryListsAreIndependent() {
Gson original = new Gson(CUSTOM_EXCLUDER, CUSTOM_FIELD_NAMING_STRATEGY,
new HashMap<Type, InstanceCreator<?>>(), true, false, true, false,
new HashMap<Type, InstanceCreator<?>>(), true, false, true, false, false,
FormattingStyle.PRETTY, Strictness.LENIENT, false, false, true,
LongSerializationPolicy.DEFAULT, null, DateFormat.DEFAULT,
DateFormat.DEFAULT, new ArrayList<TypeAdapterFactory>(),

View File

@ -222,7 +222,7 @@ public final class MixedStreamTest {
StringWriter writer = new StringWriter();
JsonWriter jsonWriter = new JsonWriter(writer);
new GsonBuilder().setLenient().serializeSpecialFloatingPointValues().create()
new GsonBuilder().setStrictness(Strictness.LENIENT).serializeSpecialFloatingPointValues().create()
.toJson(doubles, type, jsonWriter);
assertThat(writer.toString()).isEqualTo("[NaN,-Infinity,Infinity,-0.0,0.5,0.0]");

View File

@ -98,19 +98,19 @@ public class ToNumberPolicyTest {
@Test
public void testNullsAreNeverExpected() throws IOException {
IllegalStateException e = assertThrows(IllegalStateException.class, () -> ToNumberPolicy.DOUBLE.readNumber(fromString("null")));
assertThat(e).hasMessageThat().isEqualTo("Expected a double but was NULL at line 1 column 5 path $"
assertThat(e).hasMessageThat().isEqualTo("Expected a double but was NULL at line 1 column 5 (char '\0') path $"
+ "\nSee https://github.com/google/gson/blob/main/Troubleshooting.md#adapter-not-null-safe");
e = assertThrows(IllegalStateException.class, () -> ToNumberPolicy.LAZILY_PARSED_NUMBER.readNumber(fromString("null")));
assertThat(e).hasMessageThat().isEqualTo("Expected a string but was NULL at line 1 column 5 path $"
assertThat(e).hasMessageThat().isEqualTo("Expected a string but was NULL at line 1 column 5 (char '\0') path $"
+ "\nSee https://github.com/google/gson/blob/main/Troubleshooting.md#adapter-not-null-safe");
e = assertThrows(IllegalStateException.class, () -> ToNumberPolicy.LONG_OR_DOUBLE.readNumber(fromString("null")));
assertThat(e).hasMessageThat().isEqualTo("Expected a string but was NULL at line 1 column 5 path $"
assertThat(e).hasMessageThat().isEqualTo("Expected a string but was NULL at line 1 column 5 (char '\0') path $"
+ "\nSee https://github.com/google/gson/blob/main/Troubleshooting.md#adapter-not-null-safe");
e = assertThrows(IllegalStateException.class, () -> ToNumberPolicy.BIG_DECIMAL.readNumber(fromString("null")));
assertThat(e).hasMessageThat().isEqualTo("Expected a string but was NULL at line 1 column 5 path $"
assertThat(e).hasMessageThat().isEqualTo("Expected a string but was NULL at line 1 column 5 (char '\0') path $"
+ "\nSee https://github.com/google/gson/blob/main/Troubleshooting.md#adapter-not-null-safe");
}

View File

@ -18,7 +18,6 @@ package com.google.gson;
import static com.google.common.truth.Truth.assertThat;
import com.google.errorprone.annotations.Keep;
import com.google.gson.annotations.Since;
import com.google.gson.annotations.Until;
import com.google.gson.internal.Excluder;
@ -76,7 +75,6 @@ public class VersionExclusionStrategyTest {
private static class MockClassSince {
@Since(VERSION)
@Keep
public final int someField = 0;
}
@ -84,7 +82,6 @@ public class VersionExclusionStrategyTest {
private static class MockClassUntil {
@Until(VERSION)
@Keep
public final int someField = 0;
}
@ -94,7 +91,6 @@ public class VersionExclusionStrategyTest {
@Since(VERSION)
@Until(VERSION + 2)
@Keep
public final int someField = 0;
}
}

View File

@ -18,13 +18,7 @@ package com.google.gson.functional;
import static com.google.common.truth.Truth.assertThat;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import com.google.gson.*;
import com.google.gson.common.TestTypes.Base;
import com.google.gson.common.TestTypes.ClassWithBaseField;
import java.lang.reflect.Type;
@ -116,7 +110,7 @@ public class CustomDeserializerTest {
public void testJsonTypeFieldBasedDeserialization() {
String json = "{field1:'abc',field2:'def',__type__:'SUB_TYPE1'}";
Gson gson = new GsonBuilder()
.setLenient()
.setStrictness(Strictness.LENIENT)
.registerTypeAdapter(MyBase.class, (JsonDeserializer<MyBase>) (json1, pojoType, context) -> {
String type = json1.getAsJsonObject().get(MyBase.TYPE_ACCESS).getAsString();
return context.deserialize(json1, SubTypes.valueOf(type).getSubclass());
@ -154,7 +148,7 @@ public class CustomDeserializerTest {
@Test
public void testCustomDeserializerReturnsNullForTopLevelObject() {
Gson gson = new GsonBuilder()
.setLenient()
.setStrictness(Strictness.LENIENT)
.registerTypeAdapter(Base.class, (JsonDeserializer<Base>) (json, typeOfT, context) -> null).create();
String json = "{baseName:'Base',subName:'SubRevised'}";
Base target = gson.fromJson(json, Base.class);
@ -164,7 +158,7 @@ public class CustomDeserializerTest {
@Test
public void testCustomDeserializerReturnsNull() {
Gson gson = new GsonBuilder()
.setLenient()
.setStrictness(Strictness.LENIENT)
.registerTypeAdapter(Base.class, (JsonDeserializer<Base>) (json, typeOfT, context) -> null).create();
String json = "{base:{baseName:'Base',subName:'SubRevised'}}";
ClassWithBaseField target = gson.fromJson(json, ClassWithBaseField.class);
@ -174,7 +168,7 @@ public class CustomDeserializerTest {
@Test
public void testCustomDeserializerReturnsNullForArrayElements() {
Gson gson = new GsonBuilder()
.setLenient()
.setStrictness(Strictness.LENIENT)
.registerTypeAdapter(Base.class, (JsonDeserializer<Base>) (json, typeOfT, context) -> null).create();
String json = "[{baseName:'Base'},{baseName:'Base'}]";
Base[] target = gson.fromJson(json, Base[].class);
@ -185,7 +179,7 @@ public class CustomDeserializerTest {
@Test
public void testCustomDeserializerReturnsNullForArrayElementsForArrayField() {
Gson gson = new GsonBuilder()
.setLenient()
.setStrictness(Strictness.LENIENT)
.registerTypeAdapter(Base.class, (JsonDeserializer<Base>) (json, typeOfT, context) -> null).create();
String json = "{bases:[{baseName:'Base'},{baseName:'Base'}]}";
ClassWithBaseArray target = gson.fromJson(json, ClassWithBaseArray.class);

View File

@ -18,17 +18,7 @@ package com.google.gson.functional;
import static com.google.common.truth.Truth.assertThat;
import com.google.common.base.Splitter;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.InstanceCreator;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import com.google.gson.*;
import com.google.gson.common.TestTypes.BagOfPrimitives;
import com.google.gson.common.TestTypes.ClassWithCustomTypeConverter;
import com.google.gson.reflect.TypeToken;
@ -418,7 +408,7 @@ public class CustomTypeAdaptersTest {
@Test
public void testEnsureCustomDeserializerNotInvokedForNullValues() {
Gson gson = new GsonBuilder()
.setLenient()
.setStrictness(Strictness.LENIENT)
.registerTypeAdapter(DataHolder.class, new DataHolderDeserializer())
.create();
String json = "{wrappedData:null}";

View File

@ -18,18 +18,7 @@ package com.google.gson.functional;
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.fail;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonArray;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonNull;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSyntaxException;
import com.google.gson.TypeAdapter;
import com.google.gson.*;
import com.google.gson.internal.JavaVersion;
import com.google.gson.reflect.TypeToken;
import com.google.gson.stream.JsonReader;
@ -113,7 +102,7 @@ public class DefaultTypeAdaptersTest {
+ "\nSee https://github.com/google/gson/blob/main/Troubleshooting.md#java-lang-class-unsupported");
}
// Override with a custom type adapter for class.
gson = new GsonBuilder().setLenient().registerTypeAdapter(Class.class, new MyClassTypeAdapter()).create();
gson = new GsonBuilder().setStrictness(Strictness.LENIENT).registerTypeAdapter(Class.class, new MyClassTypeAdapter()).create();
assertThat(gson.fromJson("java.lang.String", Class.class)).isAssignableTo(String.class);
}

View File

@ -22,6 +22,7 @@ import com.google.errorprone.annotations.Keep;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.InstanceCreator;
import com.google.gson.Strictness;
import com.google.gson.annotations.Expose;
import java.lang.reflect.Type;
import org.junit.Before;
@ -39,7 +40,7 @@ public class ExposeFieldsTest {
@Before
public void setUp() throws Exception {
gson = new GsonBuilder()
.setLenient()
.setStrictness(Strictness.LENIENT)
.excludeFieldsWithoutExposeAnnotation()
.registerTypeAdapter(SomeInterface.class, new SomeInterfaceInstanceCreator())
.create();

View File

@ -71,7 +71,7 @@ public class FormattingStyleTest {
@Test
public void testVariousCombinationsParse() {
// Mixing various indent and newline styles in the same string, to be parsed.
String jsonStringMix = "{\r\t'a':\r\n[ 1,2\t]\n}";
String jsonStringMix = "{\r\t\"a\":\r\n[ 1,2\t]\n}";
TypeToken<Map<String, List<Integer>>> inputType = new TypeToken<Map<String, List<Integer>>>() {};
Map<String, List<Integer>> actualParsed;

View File

@ -21,6 +21,7 @@ import static com.google.common.truth.Truth.assertThat;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.InstanceCreator;
import com.google.gson.Strictness;
import com.google.gson.common.TestTypes.Base;
import com.google.gson.common.TestTypes.ClassWithBaseField;
import com.google.gson.common.TestTypes.Sub;
@ -43,7 +44,7 @@ public class InstanceCreatorTest {
@Test
public void testInstanceCreatorReturnsBaseType() {
Gson gson = new GsonBuilder()
.setLenient()
.setStrictness(Strictness.LENIENT)
.registerTypeAdapter(Base.class, (InstanceCreator<Base>) type -> new Base())
.create();
String json = "{baseName:'BaseRevised',subName:'Sub'}";
@ -54,7 +55,7 @@ public class InstanceCreatorTest {
@Test
public void testInstanceCreatorReturnsSubTypeForTopLevelObject() {
Gson gson = new GsonBuilder()
.setLenient()
.setStrictness(Strictness.LENIENT)
.registerTypeAdapter(Base.class, (InstanceCreator<Base>) type -> new Sub())
.create();
@ -70,7 +71,7 @@ public class InstanceCreatorTest {
@Test
public void testInstanceCreatorReturnsSubTypeForField() {
Gson gson = new GsonBuilder()
.setLenient()
.setStrictness(Strictness.LENIENT)
.registerTypeAdapter(Base.class, (InstanceCreator<Base>) type -> new Sub())
.create();
String json = "{base:{baseName:'Base',subName:'SubRevised'}}";

View File

@ -20,18 +20,7 @@ import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.fail;
import com.google.common.base.Splitter;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.InstanceCreator;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonParseException;
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import com.google.gson.TypeAdapter;
import com.google.gson.TypeAdapterFactory;
import com.google.gson.*;
import com.google.gson.annotations.JsonAdapter;
import com.google.gson.reflect.TypeToken;
import com.google.gson.stream.JsonReader;
@ -105,7 +94,7 @@ public final class JsonAdapterAnnotationOnClassesTest {
}
};
Gson gson = new GsonBuilder()
.setLenient()
.setStrictness(Strictness.LENIENT)
.registerTypeAdapter(A.class, serializer)
.create();
String json = gson.toJson(new A("abcd"));
@ -126,7 +115,7 @@ public final class JsonAdapterAnnotationOnClassesTest {
}
};
Gson gson = new GsonBuilder()
.setLenient()
.setStrictness(Strictness.LENIENT)
.registerTypeAdapter(A.class, deserializer)
.create();
String json = gson.toJson(new A("abcd"));

View File

@ -18,18 +18,7 @@ package com.google.gson.functional;
import static com.google.common.truth.Truth.assertThat;
import com.google.gson.ExclusionStrategy;
import com.google.gson.FieldAttributes;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import com.google.gson.TypeAdapter;
import com.google.gson.TypeAdapterFactory;
import com.google.gson.*;
import com.google.gson.annotations.JsonAdapter;
import com.google.gson.internal.bind.ReflectiveTypeAdapterFactory;
import com.google.gson.reflect.TypeToken;
@ -78,7 +67,7 @@ public final class JsonAdapterAnnotationOnFieldsTest {
@Test
public void testFieldAnnotationTakesPrecedenceOverRegisteredTypeAdapter() {
Gson gson = new GsonBuilder()
.setLenient()
.setStrictness(Strictness.LENIENT)
.registerTypeAdapter(Part.class, new TypeAdapter<Part>() {
@Override public void write(JsonWriter out, Part part) {
throw new AssertionError();

View File

@ -22,6 +22,7 @@ import static org.junit.Assert.fail;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonSyntaxException;
import com.google.gson.Strictness;
import com.google.gson.reflect.TypeToken;
import java.lang.reflect.Type;
import java.util.HashMap;
@ -116,7 +117,7 @@ public class MapAsArrayTypeAdapterTest {
@Test
public void testMapWithTypeVariableDeserialization() {
Gson gson = new GsonBuilder().setLenient().enableComplexMapKeySerialization().create();
Gson gson = new GsonBuilder().setStrictness(Strictness.LENIENT).enableComplexMapKeySerialization().create();
String json = "{map:[[{x:2,y:3},{x:4,y:5}]]}";
Type type = new TypeToken<PointWithProperty<Point>>(){}.getType();
PointWithProperty<Point> map = gson.fromJson(json, type);

View File

@ -18,15 +18,7 @@ package com.google.gson.functional;
import static com.google.common.truth.Truth.assertThat;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonNull;
import com.google.gson.JsonObject;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import com.google.gson.*;
import com.google.gson.common.TestTypes.BagOfPrimitives;
import com.google.gson.common.TestTypes.ClassWithObjects;
import java.lang.reflect.Type;
@ -240,7 +232,7 @@ public class NullObjectAndFieldTest {
@Test
public void testCustomTypeAdapterPassesNullDesrialization() {
Gson gson = new GsonBuilder()
.setLenient()
.setStrictness(Strictness.LENIENT)
.registerTypeAdapter(ObjectWithField.class, (JsonDeserializer<ObjectWithField>) (json, type, context) -> context.deserialize(null, type)).create();
String json = "{value:'value1'}";
ObjectWithField target = gson.fromJson(json, ObjectWithField.class);

View File

@ -544,7 +544,7 @@ public class PrimitiveTest {
@Test
public void testDoubleNaNSerialization() {
Gson gson = new GsonBuilder().setLenient().serializeSpecialFloatingPointValues().create();
Gson gson = new GsonBuilder().setStrictness(Strictness.LENIENT).serializeSpecialFloatingPointValues().create();
double nan = Double.NaN;
assertThat(gson.toJson(nan)).isEqualTo("NaN");
assertThat(gson.toJson(Double.NaN)).isEqualTo("NaN");
@ -573,7 +573,7 @@ public class PrimitiveTest {
@Test
public void testFloatNaNSerialization() {
Gson gson = new GsonBuilder().setLenient().serializeSpecialFloatingPointValues().create();
Gson gson = new GsonBuilder().setStrictness(Strictness.LENIENT).serializeSpecialFloatingPointValues().create();
float nan = Float.NaN;
assertThat(gson.toJson(nan)).isEqualTo("NaN");
assertThat(gson.toJson(Float.NaN)).isEqualTo("NaN");
@ -611,7 +611,7 @@ public class PrimitiveTest {
@Test
public void testDoubleInfinitySerialization() {
Gson gson = new GsonBuilder().setLenient().serializeSpecialFloatingPointValues().create();
Gson gson = new GsonBuilder().setStrictness(Strictness.LENIENT).serializeSpecialFloatingPointValues().create();
double infinity = Double.POSITIVE_INFINITY;
assertThat(gson.toJson(infinity)).isEqualTo("Infinity");
assertThat(gson.toJson(Double.POSITIVE_INFINITY)).isEqualTo("Infinity");
@ -640,7 +640,7 @@ public class PrimitiveTest {
@Test
public void testFloatInfinitySerialization() {
Gson gson = new GsonBuilder().setLenient().serializeSpecialFloatingPointValues().create();
Gson gson = new GsonBuilder().setStrictness(Strictness.LENIENT).serializeSpecialFloatingPointValues().create();
float infinity = Float.POSITIVE_INFINITY;
assertThat(gson.toJson(infinity)).isEqualTo("Infinity");
assertThat(gson.toJson(Float.POSITIVE_INFINITY)).isEqualTo("Infinity");
@ -678,7 +678,7 @@ public class PrimitiveTest {
@Test
public void testNegativeInfinitySerialization() {
Gson gson = new GsonBuilder().setLenient().serializeSpecialFloatingPointValues().create();
Gson gson = new GsonBuilder().setStrictness(Strictness.LENIENT).serializeSpecialFloatingPointValues().create();
double negativeInfinity = Double.NEGATIVE_INFINITY;
assertThat(gson.toJson(negativeInfinity)).isEqualTo("-Infinity");
assertThat(gson.toJson(Double.NEGATIVE_INFINITY)).isEqualTo("-Infinity");
@ -707,7 +707,7 @@ public class PrimitiveTest {
@Test
public void testNegativeInfinityFloatSerialization() {
Gson gson = new GsonBuilder().setLenient().serializeSpecialFloatingPointValues().create();
Gson gson = new GsonBuilder().setStrictness(Strictness.LENIENT).serializeSpecialFloatingPointValues().create();
float negativeInfinity = Float.NEGATIVE_INFINITY;
assertThat(gson.toJson(negativeInfinity)).isEqualTo("-Infinity");
assertThat(gson.toJson(Float.NEGATIVE_INFINITY)).isEqualTo("-Infinity");

View File

@ -44,6 +44,20 @@ public class ReflectionAccessTest {
}
}
private static JsonIOException assertInaccessibleException(String json, Class<?> toDeserialize) {
Gson gson = new Gson();
try {
gson.fromJson(json, toDeserialize);
throw new AssertionError("Missing exception; test has to be run with `--illegal-access=deny`");
} catch (JsonSyntaxException e) {
throw new AssertionError("Unexpected exception; test has to be run with `--illegal-access=deny`", e);
} catch (JsonIOException expected) {
assertThat(expected).hasMessageThat().endsWith("\nSee https://github.com/google/gson/blob/main/Troubleshooting.md#reflection-inaccessible");
// Return exception for further assertions
return expected;
}
}
/**
* Test serializing an instance of a non-accessible internal class, but where
* Gson supports serializing one of its superinterfaces.

View File

@ -20,6 +20,7 @@ import static com.google.common.truth.Truth.assertThat;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.Strictness;
import com.google.gson.common.TestTypes.BagOfPrimitives;
import org.junit.Before;
import org.junit.Test;
@ -39,7 +40,7 @@ public class SecurityTest {
@Before
public void setUp() throws Exception {
gsonBuilder = new GsonBuilder().setLenient();
gsonBuilder = new GsonBuilder().setStrictness(Strictness.LENIENT);
}
@Test

View File

@ -20,13 +20,7 @@ import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.fail;
import com.google.common.base.Splitter;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSyntaxException;
import com.google.gson.TypeAdapter;
import com.google.gson.*;
import com.google.gson.reflect.TypeToken;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
@ -179,7 +173,7 @@ public final class StreamingTypeAdaptersTest {
out.value(person.name + "," + person.age);
}
};
Gson gson = new GsonBuilder().setLenient().registerTypeAdapter(
Gson gson = new GsonBuilder().setStrictness(Strictness.LENIENT).registerTypeAdapter(
Person.class, typeAdapter).create();
Truck truck = new Truck();
truck.horsePower = 1.0D;
@ -195,10 +189,10 @@ public final class StreamingTypeAdaptersTest {
gson.fromJson(json, Truck.class);
fail();
} catch (JsonSyntaxException expected) {
assertThat(expected).hasMessageThat().isEqualTo("java.lang.IllegalStateException: Expected a string but was NULL at line 1 column 33 path $.passengers[0]"
assertThat(expected).hasMessageThat().isEqualTo("java.lang.IllegalStateException: Expected a string but was NULL at line 1 column 33 (char ',') path $.passengers[0]"
+ "\nSee https://github.com/google/gson/blob/main/Troubleshooting.md#adapter-not-null-safe");
}
gson = new GsonBuilder().setLenient().registerTypeAdapter(Person.class, typeAdapter.nullSafe()).create();
gson = new GsonBuilder().setStrictness(Strictness.LENIENT).registerTypeAdapter(Person.class, typeAdapter.nullSafe()).create();
assertThat(gson.toJson(truck, Truck.class))
.isEqualTo("{\"horsePower\":1.0,\"passengers\":[null,\"jesse,30\"]}");
truck = gson.fromJson(json, Truck.class);

View File

@ -18,15 +18,7 @@ package com.google.gson.functional;
import static com.google.common.truth.Truth.assertThat;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonParseException;
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import com.google.gson.*;
import com.google.gson.reflect.TypeToken;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
@ -55,7 +47,7 @@ public class TreeTypeAdaptersTest {
@Before
public void setUp() {
gson = new GsonBuilder()
.setLenient()
.setStrictness(Strictness.LENIENT)
.registerTypeAdapter(Id.class, new IdTreeTypeAdapter())
.create();
course = new Course<>(COURSE_ID, 4,

View File

@ -18,15 +18,7 @@ package com.google.gson.functional;
import static com.google.common.truth.Truth.assertThat;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import com.google.gson.TypeAdapter;
import com.google.gson.*;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
import java.io.IOException;
@ -37,7 +29,7 @@ public final class TypeAdapterPrecedenceTest {
@Test
public void testNonstreamingFollowedByNonstreaming() {
Gson gson = new GsonBuilder()
.setLenient()
.setStrictness(Strictness.LENIENT)
.registerTypeAdapter(Foo.class, newSerializer("serializer 1"))
.registerTypeAdapter(Foo.class, newSerializer("serializer 2"))
.registerTypeAdapter(Foo.class, newDeserializer("deserializer 1"))
@ -50,7 +42,7 @@ public final class TypeAdapterPrecedenceTest {
@Test
public void testStreamingFollowedByStreaming() {
Gson gson = new GsonBuilder()
.setLenient()
.setStrictness(Strictness.LENIENT)
.registerTypeAdapter(Foo.class, newTypeAdapter("type adapter 1"))
.registerTypeAdapter(Foo.class, newTypeAdapter("type adapter 2"))
.create();
@ -61,7 +53,7 @@ public final class TypeAdapterPrecedenceTest {
@Test
public void testSerializeNonstreamingTypeAdapterFollowedByStreamingTypeAdapter() {
Gson gson = new GsonBuilder()
.setLenient()
.setStrictness(Strictness.LENIENT)
.registerTypeAdapter(Foo.class, newSerializer("serializer"))
.registerTypeAdapter(Foo.class, newDeserializer("deserializer"))
.registerTypeAdapter(Foo.class, newTypeAdapter("type adapter"))
@ -73,7 +65,7 @@ public final class TypeAdapterPrecedenceTest {
@Test
public void testStreamingFollowedByNonstreaming() {
Gson gson = new GsonBuilder()
.setLenient()
.setStrictness(Strictness.LENIENT)
.registerTypeAdapter(Foo.class, newTypeAdapter("type adapter"))
.registerTypeAdapter(Foo.class, newSerializer("serializer"))
.registerTypeAdapter(Foo.class, newDeserializer("deserializer"))
@ -85,7 +77,7 @@ public final class TypeAdapterPrecedenceTest {
@Test
public void testStreamingHierarchicalFollowedByNonstreaming() {
Gson gson = new GsonBuilder()
.setLenient()
.setStrictness(Strictness.LENIENT)
.registerTypeHierarchyAdapter(Foo.class, newTypeAdapter("type adapter"))
.registerTypeAdapter(Foo.class, newSerializer("serializer"))
.registerTypeAdapter(Foo.class, newDeserializer("deserializer"))
@ -108,7 +100,7 @@ public final class TypeAdapterPrecedenceTest {
@Test
public void testStreamingHierarchicalFollowedByNonstreamingHierarchical() {
Gson gson = new GsonBuilder()
.setLenient()
.setStrictness(Strictness.LENIENT)
.registerTypeHierarchyAdapter(Foo.class, newSerializer("serializer"))
.registerTypeHierarchyAdapter(Foo.class, newDeserializer("deserializer"))
.registerTypeHierarchyAdapter(Foo.class, newTypeAdapter("type adapter"))
@ -120,7 +112,7 @@ public final class TypeAdapterPrecedenceTest {
@Test
public void testNonstreamingHierarchicalFollowedByNonstreaming() {
Gson gson = new GsonBuilder()
.setLenient()
.setStrictness(Strictness.LENIENT)
.registerTypeHierarchyAdapter(Foo.class, newSerializer("hierarchical"))
.registerTypeHierarchyAdapter(Foo.class, newDeserializer("hierarchical"))
.registerTypeAdapter(Foo.class, newSerializer("non hierarchical"))

View File

@ -17,6 +17,7 @@
package com.google.gson.jf;
import com.google.gson.GsonBuilder;
import com.google.gson.Strictness;
import com.google.gson.reflect.TypeToken;
import com.google.gson.stream.JsonWriter;
import org.junit.Test;
@ -47,7 +48,7 @@ public final class CommentsTest {
+ " \"c\"\n"
+ "]";
List<String> abc = new GsonBuilder().setLenient().create().fromJson(json, new TypeToken<List<String>>() {}.getType());
List<String> abc = new GsonBuilder().setStrictness(Strictness.LENIENT).create().fromJson(json, new TypeToken<List<String>>() {}.getType());
assertThat(abc).isEqualTo(Arrays.asList("a", "b", "c"));
}
@ -70,7 +71,7 @@ public final class CommentsTest {
StringWriter sw = new StringWriter();
JsonWriter jw = new JsonWriter(sw);
jw.setLenient(true);
jw.setStrictness(Strictness.LENIENT);
jw.setIndent(" ");
jw.comment("comment at file head")

View File

@ -2,6 +2,7 @@ package com.google.gson.jf;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.Strictness;
import org.junit.Test;
import java.util.List;
@ -9,7 +10,7 @@ import java.util.List;
import static com.google.common.truth.Truth.assertThat;
public class LenientCollectionCommaTest {
private Gson lenient = new GsonBuilder().setLenient().create();
private Gson lenient = new GsonBuilder().setStrictness(Strictness.LENIENT).create();
private static final String json = "{\"collection\": [1, 2,, 3, , , 4, 5,]}";
@Test

View File

@ -3,15 +3,18 @@ package com.google.gson.jf;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonParseException;
import com.google.gson.Strictness;
import org.junit.Test;
import java.lang.reflect.Field;
import java.util.List;
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThrows;
public class LenientCollectionTest {
private Gson lenient = new GsonBuilder().setLenient().create();
private Gson lenient = new GsonBuilder().setStrictness(Strictness.LENIENT).create();
private Gson strict = new GsonBuilder().create();
private static final String json = "{\"collection\": \"example\"}";
@ -28,7 +31,7 @@ public class LenientCollectionTest {
}
@Test
public void testStrictArray() {
public void testStrictArray() throws NoSuchFieldException, IllegalAccessException {
assertThrows("Strict Gson should not deserialize array without brackets",
JsonParseException.class,
() -> strict.fromJson(json, Box.StringArray.class));

View File

@ -2,6 +2,7 @@ package com.google.gson.jf;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.Strictness;
import com.google.gson.stream.JsonReader;
import org.junit.Test;
@ -14,7 +15,7 @@ import static com.google.common.truth.Truth.assertThat;
public class ReadNullTest {
@Test
public void testReadNull() throws IOException {
Gson gson = new GsonBuilder().serializeNulls().setLenient().create();
Gson gson = new GsonBuilder().serializeNulls().setStrictness(Strictness.LENIENT).create();
String exampleFile = "{\n // Yes\n \"value1\": 1024,\n \"value2\": null,\n \"value3\": 10\n}";
try (Reader r = new StringReader(exampleFile); JsonReader jr = gson.newJsonReader(r)) {
jr.beginObject();

View File

@ -134,14 +134,14 @@ public final class JsonReaderTest {
IOException expected = assertThrows(IOException.class, reader::nextBoolean);
assertThat(expected).hasMessageThat().startsWith("Use JsonReader.setStrictness(Strictness.LENIENT) to accept malformed" +
" JSON at line 1 column 1 path $");
" JSON at line 1 column 1 (char 'T') path $");
reader = new JsonReader(reader("True"));
reader.setStrictness(Strictness.STRICT);
expected = assertThrows(IOException.class, reader::nextBoolean);
assertThat(expected).hasMessageThat().startsWith("Use JsonReader.setStrictness(Strictness.LENIENT) to accept malformed" +
" JSON at line 1 column 1 path $");
" JSON at line 1 column 1 (char 'T') path $");
}
@Test
@ -151,14 +151,14 @@ public final class JsonReaderTest {
IOException expected = assertThrows(IOException.class, reader::nextBoolean);
assertThat(expected).hasMessageThat().startsWith("Use JsonReader.setStrictness(Strictness.LENIENT) to accept malformed" +
" JSON at line 1 column 1 path $");
" JSON at line 1 column 1 (char 'F') path $");
reader = new JsonReader(reader("FaLse"));
reader.setStrictness(Strictness.STRICT);
expected = assertThrows(IOException.class, reader::nextBoolean);
assertThat(expected).hasMessageThat().startsWith("Use JsonReader.setStrictness(Strictness.LENIENT) to accept malformed" +
" JSON at line 1 column 1 path $");
" JSON at line 1 column 1 (char 'F') path $");
}
@Test
@ -168,14 +168,14 @@ public final class JsonReaderTest {
IOException expected = assertThrows(IOException.class, reader::nextNull);
assertThat(expected).hasMessageThat().startsWith("Use JsonReader.setStrictness(Strictness.LENIENT) to accept malformed" +
" JSON at line 1 column 1 path $");
" JSON at line 1 column 1 (char 'N') path $");
reader = new JsonReader(reader("nulL"));
reader.setStrictness(Strictness.STRICT);
expected = assertThrows(IOException.class, reader::nextNull);
assertThat(expected).hasMessageThat().startsWith("Use JsonReader.setStrictness(Strictness.LENIENT) to accept malformed" +
" JSON at line 1 column 1 path $");
" JSON at line 1 column 1 (char 'n') path $");
}
@Test
@ -413,7 +413,7 @@ public final class JsonReaderTest {
reader.nextName();
fail();
} catch (MalformedJsonException expected) {
assertThat(expected).hasMessageThat().isEqualTo("Invalid escape sequence at line 2 column 8 path $."
assertThat(expected).hasMessageThat().isEqualTo("Invalid escape sequence at line 2 column 8 (char 'l') path $."
+ "\nSee https://github.com/google/gson/blob/main/Troubleshooting.md#malformed-json");
}
}
@ -542,7 +542,7 @@ public final class JsonReaderTest {
reader.nextString();
fail();
} catch (MalformedJsonException expected) {
assertThat(expected).hasMessageThat().isEqualTo("Malformed Unicode escape \\u000g at line 1 column 5 path $[0]"
assertThat(expected).hasMessageThat().isEqualTo("Malformed Unicode escape \\u000g at line 1 column 5 (char '0') path $[0]"
+ "\nSee https://github.com/google/gson/blob/main/Troubleshooting.md#malformed-json");
}
}
@ -556,7 +556,7 @@ public final class JsonReaderTest {
reader.nextString();
fail();
} catch (MalformedJsonException expected) {
assertThat(expected).hasMessageThat().isEqualTo("Unterminated escape sequence at line 1 column 5 path $[0]"
assertThat(expected).hasMessageThat().isEqualTo("Unterminated escape sequence at line 1 column 5 (char '0') path $[0]"
+ "\nSee https://github.com/google/gson/blob/main/Troubleshooting.md#malformed-json");
}
}
@ -570,7 +570,7 @@ public final class JsonReaderTest {
reader.nextString();
fail();
} catch (MalformedJsonException expected) {
assertThat(expected).hasMessageThat().isEqualTo("Unterminated escape sequence at line 1 column 4 path $[0]"
assertThat(expected).hasMessageThat().isEqualTo("Unterminated escape sequence at line 1 column 4 (char '[') path $[0]"
+ "\nSee https://github.com/google/gson/blob/main/Troubleshooting.md#malformed-json");
}
}
@ -637,7 +637,7 @@ public final class JsonReaderTest {
reader.nextDouble();
fail();
} catch (MalformedJsonException expected) {
assertStrictError(expected, "line 1 column 2 path $[0]");
assertStrictError(expected, "line 1 column 2 (char 'N') path $[0]");
}
}
@ -650,7 +650,7 @@ public final class JsonReaderTest {
reader.nextDouble();
fail();
} catch (MalformedJsonException expected) {
assertThat(expected).hasMessageThat().isEqualTo("JSON forbids NaN and infinities: NaN at line 1 column 7 path $[0]"
assertThat(expected).hasMessageThat().isEqualTo("JSON forbids NaN and infinities: NaN at line 1 column 7 (char ']') path $[0]"
+ "\nSee https://github.com/google/gson/blob/main/Troubleshooting.md#malformed-json");
}
}
@ -688,7 +688,7 @@ public final class JsonReaderTest {
reader.skipValue();
fail();
} catch (MalformedJsonException expected) {
assertStrictError(expected, "line 1 column 2 path $[0]");
assertStrictError(expected, "line 1 column 2 (char 'N') path $[0]");
}
}
@ -781,7 +781,7 @@ public final class JsonReaderTest {
reader.nextBoolean();
fail();
} catch (IllegalStateException expected) {
assertUnexpectedStructureError(expected, "a boolean", "STRING", "line 1 column 2 path $[0]");
assertUnexpectedStructureError(expected, "a boolean", "STRING", "line 1 column 2 (char 't') path $[0]");
}
assertThat(reader.nextString()).isEqualTo("truey");
reader.endArray();
@ -1018,7 +1018,7 @@ public final class JsonReaderTest {
reader.nextString();
fail();
} catch (MalformedJsonException expected) {
assertThat(expected).hasMessageThat().isEqualTo("Expected value at line 1 column 6 path $.a"
assertThat(expected).hasMessageThat().isEqualTo("Expected value at line 1 column 6 (char '}') path $.a"
+ "\nSee https://github.com/google/gson/blob/main/Troubleshooting.md#malformed-json");
}
}
@ -1078,63 +1078,63 @@ public final class JsonReaderTest {
String unused = reader.nextString();
fail();
} catch (IllegalStateException expected) {
assertUnexpectedStructureError(expected, "a string", "NAME", "line 1 column 3 path $.");
assertUnexpectedStructureError(expected, "a string", "NAME", "line 1 column 3 (char 'a') path $.");
}
assertThat(reader.nextName()).isEqualTo("a");
try {
String unused = reader.nextName();
fail();
} catch (IllegalStateException expected) {
assertUnexpectedStructureError(expected, "a name", "BOOLEAN", "line 1 column 10 path $.a");
assertUnexpectedStructureError(expected, "a name", "BOOLEAN", "line 1 column 10 (char '}') path $.a");
}
try {
reader.beginArray();
fail();
} catch (IllegalStateException expected) {
assertUnexpectedStructureError(expected, "BEGIN_ARRAY", "BOOLEAN", "line 1 column 10 path $.a");
assertUnexpectedStructureError(expected, "BEGIN_ARRAY", "BOOLEAN", "line 1 column 10 (char '}') path $.a");
}
try {
reader.endArray();
fail();
} catch (IllegalStateException expected) {
assertUnexpectedStructureError(expected, "END_ARRAY", "BOOLEAN", "line 1 column 10 path $.a");
assertUnexpectedStructureError(expected, "END_ARRAY", "BOOLEAN", "line 1 column 10 (char '}') path $.a");
}
try {
reader.beginObject();
fail();
} catch (IllegalStateException expected) {
assertUnexpectedStructureError(expected, "BEGIN_OBJECT", "BOOLEAN", "line 1 column 10 path $.a");
assertUnexpectedStructureError(expected, "BEGIN_OBJECT", "BOOLEAN", "line 1 column 10 (char '}') path $.a");
}
try {
reader.endObject();
fail();
} catch (IllegalStateException expected) {
assertUnexpectedStructureError(expected, "END_OBJECT", "BOOLEAN", "line 1 column 10 path $.a");
assertUnexpectedStructureError(expected, "END_OBJECT", "BOOLEAN", "line 1 column 10 (char '}') path $.a");
}
assertThat(reader.nextBoolean()).isTrue();
try {
reader.nextString();
fail();
} catch (IllegalStateException expected) {
assertUnexpectedStructureError(expected, "a string", "END_OBJECT", "line 1 column 11 path $.a");
assertUnexpectedStructureError(expected, "a string", "END_OBJECT", "line 1 column 11 (char '\0') path $.a");
}
try {
reader.nextName();
fail();
} catch (IllegalStateException expected) {
assertUnexpectedStructureError(expected, "a name", "END_OBJECT", "line 1 column 11 path $.a");
assertUnexpectedStructureError(expected, "a name", "END_OBJECT", "line 1 column 11 (char '\0') path $.a");
}
try {
reader.beginArray();
fail();
} catch (IllegalStateException expected) {
assertUnexpectedStructureError(expected, "BEGIN_ARRAY", "END_OBJECT", "line 1 column 11 path $.a");
assertUnexpectedStructureError(expected, "BEGIN_ARRAY", "END_OBJECT", "line 1 column 11 (char '\0') path $.a");
}
try {
reader.endArray();
fail();
} catch (IllegalStateException expected) {
assertUnexpectedStructureError(expected, "END_ARRAY", "END_OBJECT", "line 1 column 11 path $.a");
assertUnexpectedStructureError(expected, "END_ARRAY", "END_OBJECT", "line 1 column 11 (char '\0') path $.a");
}
reader.endObject();
assertThat(reader.peek()).isEqualTo(JsonToken.END_DOCUMENT);
@ -1162,7 +1162,7 @@ public final class JsonReaderTest {
reader.nextNull();
fail();
} catch (IllegalStateException expected) {
assertUnexpectedStructureError(expected, "null", "STRING", "line 1 column 3 path $[0]");
assertUnexpectedStructureError(expected, "null", "STRING", "line 1 column 3 (char 'n') path $[0]");
}
}
@ -1174,7 +1174,7 @@ public final class JsonReaderTest {
reader.nextString();
fail();
} catch (IllegalStateException expected) {
assertUnexpectedStructureError(expected, "a string", "NULL", "line 1 column 6 path $[0]");
assertUnexpectedStructureError(expected, "a string", "NULL", "line 1 column 6 (char ']') path $[0]");
}
}
@ -1187,7 +1187,7 @@ public final class JsonReaderTest {
reader.nextBoolean();
fail();
} catch (MalformedJsonException expected) {
assertStrictError(expected, "line 1 column 6 path $.a");
assertStrictError(expected, "line 1 column 6 (char 't') path $.a");
}
reader = new JsonReader(reader("{\"a\"=>true}"));
@ -1197,7 +1197,7 @@ public final class JsonReaderTest {
reader.nextBoolean();
fail();
} catch (MalformedJsonException expected) {
assertStrictError(expected, "line 1 column 6 path $.a");
assertStrictError(expected, "line 1 column 6 (char '>') path $.a");
}
}
@ -1225,7 +1225,7 @@ public final class JsonReaderTest {
reader.skipValue();
fail();
} catch (MalformedJsonException expected) {
assertStrictError(expected, "line 1 column 6 path $.a");
assertStrictError(expected, "line 1 column 6 (char 't') path $.a");
}
reader = new JsonReader(reader("{\"a\"=>true}"));
@ -1235,7 +1235,7 @@ public final class JsonReaderTest {
reader.skipValue();
fail();
} catch (MalformedJsonException expected) {
assertStrictError(expected, "line 1 column 6 path $.a");
assertStrictError(expected, "line 1 column 6 (char '>') path $.a");
}
}
@ -1267,7 +1267,7 @@ public final class JsonReaderTest {
reader.nextBoolean();
fail();
} catch (MalformedJsonException expected) {
assertStrictError(expected, "line 1 column 3 path $[0]");
assertStrictError(expected, "line 1 column 3 (char '/') path $[0]");
}
reader = new JsonReader(reader("[# comment \n true]"));
@ -1276,7 +1276,7 @@ public final class JsonReaderTest {
reader.nextBoolean();
fail();
} catch (MalformedJsonException expected) {
assertStrictError(expected, "line 1 column 3 path $[0]");
assertStrictError(expected, "line 1 column 3 (char ' ') path $[0]");
}
reader = new JsonReader(reader("[/* comment */ true]"));
@ -1285,7 +1285,7 @@ public final class JsonReaderTest {
reader.nextBoolean();
fail();
} catch (MalformedJsonException expected) {
assertStrictError(expected, "line 1 column 3 path $[0]");
assertStrictError(expected, "line 1 column 3 (char '*') path $[0]");
}
}
@ -1315,7 +1315,7 @@ public final class JsonReaderTest {
reader.skipValue();
fail();
} catch (MalformedJsonException expected) {
assertStrictError(expected, "line 1 column 3 path $[0]");
assertStrictError(expected, "line 1 column 3 (char '/') path $[0]");
}
reader = new JsonReader(reader("[# comment \n true]"));
@ -1324,7 +1324,7 @@ public final class JsonReaderTest {
reader.skipValue();
fail();
} catch (MalformedJsonException expected) {
assertStrictError(expected, "line 1 column 3 path $[0]");
assertStrictError(expected, "line 1 column 3 (char ' ') path $[0]");
}
reader = new JsonReader(reader("[/* comment */ true]"));
@ -1333,7 +1333,7 @@ public final class JsonReaderTest {
reader.skipValue();
fail();
} catch (MalformedJsonException expected) {
assertStrictError(expected, "line 1 column 3 path $[0]");
assertStrictError(expected, "line 1 column 3 (char '*') path $[0]");
}
}
@ -1345,7 +1345,7 @@ public final class JsonReaderTest {
reader.nextName();
fail();
} catch (MalformedJsonException expected) {
assertStrictError(expected, "line 1 column 3 path $.");
assertStrictError(expected, "line 1 column 3 (char ':') path $.");
}
}
@ -1365,7 +1365,7 @@ public final class JsonReaderTest {
reader.skipValue();
fail();
} catch (MalformedJsonException expected) {
assertStrictError(expected, "line 1 column 3 path $.");
assertStrictError(expected, "line 1 column 3 (char ':') path $.");
}
}
@ -1377,7 +1377,7 @@ public final class JsonReaderTest {
reader.nextName();
fail();
} catch (MalformedJsonException expected) {
assertStrictError(expected, "line 1 column 3 path $.");
assertStrictError(expected, "line 1 column 3 (char 'a') path $.");
}
}
@ -1397,7 +1397,7 @@ public final class JsonReaderTest {
reader.skipValue();
fail();
} catch (MalformedJsonException expected) {
assertStrictError(expected, "line 1 column 3 path $.");
assertStrictError(expected, "line 1 column 3 (char 'a') path $.");
}
}
@ -1409,7 +1409,7 @@ public final class JsonReaderTest {
reader.nextString();
fail();
} catch (MalformedJsonException expected) {
assertStrictError(expected, "line 1 column 2 path $[0]");
assertStrictError(expected, "line 1 column 2 (char 'a') path $[0]");
}
}
@ -1421,7 +1421,7 @@ public final class JsonReaderTest {
reader.skipValue();
fail();
} catch (MalformedJsonException expected) {
assertStrictError(expected, "line 1 column 2 path $[0]");
assertStrictError(expected, "line 1 column 2 (char 'a') path $[0]");
}
}
@ -1441,7 +1441,7 @@ public final class JsonReaderTest {
reader.nextString();
fail();
} catch (MalformedJsonException expected) {
assertStrictError(expected, "line 1 column 3 path $[0]");
assertStrictError(expected, "line 1 column 3 (char 'a') path $[0]");
}
}
@ -1461,7 +1461,7 @@ public final class JsonReaderTest {
reader.skipValue();
fail();
} catch (MalformedJsonException expected) {
assertStrictError(expected, "line 1 column 3 path $[0]");
assertStrictError(expected, "line 1 column 3 (char 'a') path $[0]");
}
}
@ -1473,7 +1473,7 @@ public final class JsonReaderTest {
boolean unused = reader.nextBoolean();
fail();
} catch (MalformedJsonException expected) {
assertStrictError(expected, "line 1 column 2 path $[0]");
assertStrictError(expected, "line 1 column 2 (char 't') path $[0]");
}
}
@ -1494,7 +1494,7 @@ public final class JsonReaderTest {
reader.skipValue();
fail();
} catch (MalformedJsonException expected) {
assertStrictError(expected, "line 1 column 2 path $[0]");
assertStrictError(expected, "line 1 column 2 (char 't') path $[0]");
}
}
@ -1507,7 +1507,7 @@ public final class JsonReaderTest {
boolean unused = reader.nextBoolean();
fail();
} catch (MalformedJsonException expected) {
assertStrictError(expected, "line 1 column 6 path $.a");
assertStrictError(expected, "line 1 column 6 (char 't') path $.a");
}
}
@ -1530,7 +1530,7 @@ public final class JsonReaderTest {
reader.skipValue();
fail();
} catch (MalformedJsonException expected) {
assertStrictError(expected, "line 1 column 6 path $.a");
assertStrictError(expected, "line 1 column 6 (char 't') path $.a");
}
}
@ -1543,7 +1543,7 @@ public final class JsonReaderTest {
reader.nextNull();
fail();
} catch (MalformedJsonException expected) {
assertStrictError(expected, "line 1 column 8 path $[1]");
assertStrictError(expected, "line 1 column 8 (char 't') path $[1]");
}
reader = new JsonReader(reader("[,true]"));
@ -1552,7 +1552,7 @@ public final class JsonReaderTest {
reader.nextNull();
fail();
} catch (MalformedJsonException expected) {
assertStrictError(expected, "line 1 column 3 path $[0]");
assertStrictError(expected, "line 1 column 3 (char 't') path $[0]");
}
reader = new JsonReader(reader("[true,]"));
@ -1561,8 +1561,8 @@ public final class JsonReaderTest {
try {
reader.nextNull();
fail();
} catch (MalformedJsonException expected) {
assertStrictError(expected, "line 1 column 8 path $[1]");
} catch (IllegalStateException expected) {
assertThat(expected).hasMessageThat().startsWith("Expected null but was END_ARRAY at line 1 column 8 (char '\0') path $[1]");
}
reader = new JsonReader(reader("[,]"));
@ -1571,7 +1571,7 @@ public final class JsonReaderTest {
reader.nextNull();
fail();
} catch (MalformedJsonException expected) {
assertStrictError(expected, "line 1 column 3 path $[0]");
assertStrictError(expected, "line 1 column 3 (char ']') path $[0]");
}
}
@ -1616,7 +1616,7 @@ public final class JsonReaderTest {
reader.skipValue();
fail();
} catch (MalformedJsonException expected) {
assertStrictError(expected, "line 1 column 8 path $[1]");
assertStrictError(expected, "line 1 column 8 (char 't') path $[1]");
}
reader = new JsonReader(reader("[,true]"));
@ -1625,7 +1625,7 @@ public final class JsonReaderTest {
reader.skipValue();
fail();
} catch (MalformedJsonException expected) {
assertStrictError(expected, "line 1 column 3 path $[0]");
assertStrictError(expected, "line 1 column 3 (char 't') path $[0]");
}
reader = new JsonReader(reader("[true,]"));
@ -1634,8 +1634,8 @@ public final class JsonReaderTest {
try {
reader.skipValue();
fail();
} catch (MalformedJsonException expected) {
assertStrictError(expected, "line 1 column 8 path $[1]");
} catch (IllegalStateException expected) {
assertThat(expected).hasMessageThat().isEqualTo("Attempt to skip led outside its parent");
}
reader = new JsonReader(reader("[,]"));
@ -1644,7 +1644,7 @@ public final class JsonReaderTest {
reader.skipValue();
fail();
} catch (MalformedJsonException expected) {
assertStrictError(expected, "line 1 column 3 path $[0]");
assertStrictError(expected, "line 1 column 3 (char ']') path $[0]");
}
}
@ -1657,7 +1657,7 @@ public final class JsonReaderTest {
reader.peek();
fail();
} catch (MalformedJsonException expected) {
assertStrictError(expected, "line 1 column 5 path $");
assertStrictError(expected, "line 1 column 5 (char ']') path $");
}
}
@ -1682,7 +1682,7 @@ public final class JsonReaderTest {
reader.skipValue();
fail();
} catch (MalformedJsonException expected) {
assertStrictError(expected, "line 1 column 5 path $");
assertStrictError(expected, "line 1 column 5 (char ']') path $");
}
}
@ -1728,7 +1728,7 @@ public final class JsonReaderTest {
reader.beginArray();
fail();
} catch (MalformedJsonException expected) {
assertStrictError(expected, "line 1 column 1 path $");
assertStrictError(expected, "line 1 column 1 (char ')') path $");
}
}
@ -1739,7 +1739,7 @@ public final class JsonReaderTest {
reader.skipValue();
fail();
} catch (MalformedJsonException expected) {
assertStrictError(expected, "line 1 column 1 path $");
assertStrictError(expected, "line 1 column 1 (char ')') path $");
}
}
@ -1770,7 +1770,7 @@ public final class JsonReaderTest {
reader.nextString();
fail();
} catch (MalformedJsonException expected) {
assertThat(expected).hasMessageThat().isEqualTo("Unexpected value at line 1 column 3 path $"
assertThat(expected).hasMessageThat().isEqualTo("Unexpected value at line 1 column 3 (char '}') path $"
+ "\nSee https://github.com/google/gson/blob/main/Troubleshooting.md#malformed-json");
}
}
@ -1790,7 +1790,7 @@ public final class JsonReaderTest {
reader.endArray();
fail();
} catch (MalformedJsonException expected) {
assertStrictError(expected, "line 1 column 2 path $[0]");
assertStrictError(expected, "line 1 column 2 (char '\uFEFF') path $[0]");
}
}
@ -1888,7 +1888,7 @@ public final class JsonReaderTest {
fail();
} catch (MalformedJsonException expected) {
assertThat(expected).hasMessageThat().isEqualTo(
"Expected value at line 1 column 14 path $[1].a[2]"
"Expected value at line 1 column 14 (char '}') path $[1].a[2]"
+ "\nSee https://github.com/google/gson/blob/main/Troubleshooting.md#malformed-json");
}
}
@ -1901,7 +1901,7 @@ public final class JsonReaderTest {
reader.nextDouble();
fail();
} catch (MalformedJsonException expected) {
assertStrictError(expected, "line 1 column 2 path $[0]");
assertStrictError(expected, "line 1 column 2 (char '0') path $[0]");
}
}
@ -1974,7 +1974,7 @@ public final class JsonReaderTest {
reader.peek();
fail();
} catch (MalformedJsonException expected) {
assertThat(expected).hasMessageThat().isEqualTo("Expected value at line 1 column 1 path $"
assertThat(expected).hasMessageThat().isEqualTo("Expected value at line 1 column 1 (char '/') path $"
+ "\nSee https://github.com/google/gson/blob/main/Troubleshooting.md#malformed-json");
}
}
@ -1987,7 +1987,7 @@ public final class JsonReaderTest {
reader.peek();
fail();
} catch (MalformedJsonException expected) {
assertThat(expected).hasMessageThat().isEqualTo("Expected value at line 1 column 10 path $"
assertThat(expected).hasMessageThat().isEqualTo("Expected value at line 1 column 10 (char '/') path $"
+ "\nSee https://github.com/google/gson/blob/main/Troubleshooting.md#malformed-json");
}
}
@ -2000,7 +2000,7 @@ public final class JsonReaderTest {
reader.peek();
fail();
} catch (MalformedJsonException expected) {
assertThat(expected).hasMessageThat().isEqualTo("Expected value at line 1 column 1 path $"
assertThat(expected).hasMessageThat().isEqualTo("Expected value at line 1 column 1 (char '/') path $"
+ "\nSee https://github.com/google/gson/blob/main/Troubleshooting.md#malformed-json");
}
}
@ -2016,7 +2016,7 @@ public final class JsonReaderTest {
reader.peek();
fail();
} catch (MalformedJsonException expected) {
assertThat(expected).hasMessageThat().isEqualTo("Unterminated object at line 1 column 16 path $.a"
assertThat(expected).hasMessageThat().isEqualTo("Unterminated object at x at line 1 column 16 (char '\0') path $.a"
+ "\nSee https://github.com/google/gson/blob/main/Troubleshooting.md#malformed-json");
}
}
@ -2145,7 +2145,7 @@ public final class JsonReaderTest {
reader.peek();
fail();
} catch (MalformedJsonException expected) {
assertThat(expected).hasMessageThat().isEqualTo("Expected name at line 1 column 11 path $.a"
assertThat(expected).hasMessageThat().isEqualTo("Expected name at line 1 column 11 (char '\0') path $.a"
+ "\nSee https://github.com/google/gson/blob/main/Troubleshooting.md#malformed-json");
}
}
@ -2161,7 +2161,7 @@ public final class JsonReaderTest {
reader.peek();
fail();
} catch (MalformedJsonException expected) {
assertThat(expected).hasMessageThat().isEqualTo("Expected name at line 1 column 11 path $.a"
assertThat(expected).hasMessageThat().isEqualTo("Expected name at line 1 column 11 (char '\0') path $.a"
+ "\nSee https://github.com/google/gson/blob/main/Troubleshooting.md#malformed-json");
}
}
@ -2229,7 +2229,7 @@ public final class JsonReaderTest {
reader.nextString();
fail();
} catch (MalformedJsonException expected) {
assertThat(expected).hasMessageThat().isEqualTo("Unterminated string at line 1 column 9 path $[0]"
assertThat(expected).hasMessageThat().isEqualTo("Unterminated string at line 1 column 9 (char '[') path $[0]"
+ "\nSee https://github.com/google/gson/blob/main/Troubleshooting.md#malformed-json");
}
}

44
pom.xml
View File

@ -20,7 +20,7 @@
<groupId>io.gitlab.jfronny</groupId>
<artifactId>gson-parent</artifactId>
<version>2.10.2-SNAPSHOT</version>
<version>2.10.3-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Gson Parent</name>
@ -99,36 +99,6 @@
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.4.1</version>
<executions>
<execution>
<id>enforce-versions</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireMavenVersion>
<!-- Usage of `.mvn/jvm.config` for Error Prone requires at least Maven 3.3.1 -->
<version>[3.3.1,)</version>
</requireMavenVersion>
<!-- Enforce that correct JDK version is used to avoid cryptic build errors -->
<requireJavaVersion>
<!-- Other plugins of this build require at least JDK 11 -->
<version>[11,)</version>
</requireJavaVersion>
</rules>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
@ -153,15 +123,14 @@
<configuration>
<!-- Specify newer JDK as target to allow linking to newer Java API, and to generate
module overview in Javadoc for Gson's module descriptor -->
<release>11</release>
<release>17</release>
<!-- Exclude `missing` group because some tags have been omitted when they are redundant -->
<doclint>all,-missing</doclint>
<!-- Link against newer Java API Javadoc because most users likely
use a newer Java version than the one used for building this project -->
<detectJavaApiLink>false</detectJavaApiLink>
<links>
<link>https://docs.oracle.com/en/java/javase/11/docs/api/</link>
<link>https://errorprone.info/api/latest/</link>
<link>https://docs.oracle.com/en/java/javase/17/docs/api/</link>
</links>
<!-- Disable detection of offline links between Maven modules:
(1) Only `gson` module is published, so for other modules Javadoc links don't
@ -184,15 +153,10 @@
<artifactId>maven-jar-plugin</artifactId>
<version>3.3.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>3.1.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.3.0</version>
<version>3.2.1</version>
</plugin>
</plugins>
</pluginManagement>