Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom Serializers fail if the serializer context is used on the source #43

Closed
GoogleCodeExporter opened this issue Mar 19, 2015 · 16 comments

Comments

@GoogleCodeExporter
Copy link

Gson will fail to serialize a class "Foo" if you create a custom serializer
as follows:

public static class FooTypeAdapter implements JsonSerializer<Foo> {
  public JsonElement serialize(Foo src, Type typeOfSrc,
JsonSerializationContext context) {
    return context.serialize(src, typeOfSrc);
  }
}

Basically, it detects this as a circular reference.  Instead, we should
allow this kind of custom serializer because a client may want to perform
the default serialization of an object and then add new fields into the
JsonElement tree.

For example:
public static class FooTypeAdapter implements JsonSerializer<Foo> {
  public JsonElement serialize(Foo src, Type typeOfSrc,
JsonSerializationContext context) {
    JsonElement element = context.serialize(src, typeOfSrc);
    JsonObject jsonObject = element.getAsJsonObject();
    jsonObject.add("someNewProperty", new JsonPrimitive(1L));
    return jsonObject;
  }
}

Original issue reported on code.google.com by [email protected] on 14 Sep 2008 at 7:53

@GoogleCodeExporter
Copy link
Author

I could use that, too. Basically what's missing is some kind of 
serializeInternal()
method that ignores type adapters registered for this Type.

Original comment by [email protected] on 20 Mar 2009 at 2:17

@GoogleCodeExporter
Copy link
Author

Original comment by inder123 on 28 Mar 2009 at 5:58

  • Added labels: Milestone-Release1.4

@GoogleCodeExporter
Copy link
Author

I would absolutely love this feature as well.  See this thread for related 
discussion: 
http://groups.google.com/group/google-gson/browse_thread/thread/a87d5d47b83d0cbe

Original comment by [email protected] on 17 Jul 2009 at 5:13

@GoogleCodeExporter
Copy link
Author

deferred to a future release

Original comment by inder123 on 29 Sep 2009 at 9:10

  • Added labels: Milestone-Release1.5
  • Removed labels: Milestone-Release1.4

@GoogleCodeExporter
Copy link
Author

what about cloning the src object, serializing it using context and then do all 
the 
post-processing you want?
Didn't try this though, I'm just conjecturing....

Original comment by [email protected] on 27 Apr 2010 at 4:04

@GoogleCodeExporter
Copy link
Author

Was this actually fixed?  I'm not sure it is in 1.5, even though it is marked 
with the 1.5 milestone.

Relying on clone() is a really bad idea.

Original comment by [email protected] on 26 Oct 2010 at 4:24

@GoogleCodeExporter
Copy link
Author

I could use this feature too. I do not believed it was fixed in 1.5 or current 
trunk version.

Original comment by [email protected] on 31 Oct 2010 at 3:24

@GoogleCodeExporter
Copy link
Author

Original comment by inder123 on 2 Nov 2010 at 11:59

  • Removed labels: Milestone-Release1.5

@GoogleCodeExporter
Copy link
Author

I experimented with this. We might be able to use the ancestors stack as a 
hint. Whenever a serializer+object pair exists on the ancestors stack, we 
should skip that serializer when recursively asked to serialize that object. 
We'll either eventually serialize it with a lower-level serializer, or we'll 
run out and we know we've hit a circular reference.

Original comment by limpbizkit on 9 Nov 2010 at 8:03

@GoogleCodeExporter
Copy link
Author

I would think that context.defaultWriteObject() (eg similar to the java object 
serialization mechanism) would make a lot of sense.

Original comment by [email protected] on 21 Jan 2011 at 4:58

@GoogleCodeExporter
Copy link
Author

You can do this in Gson 2.1 with TypeAdapterFactory and Gson.getNextAdapter.

Original comment by limpbizkit on 29 Dec 2011 at 5:37

  • Changed state: WontFix

@GoogleCodeExporter
Copy link
Author

Issue 44 has been merged into this issue.

Original comment by limpbizkit on 29 Dec 2011 at 5:50

@GoogleCodeExporter
Copy link
Author

Does a Gson.getNextAdapter mechanism solve the following issue?

class Obj
...

class A extends Obj
   Obj subobject;
...

Now assume we have registered:

public class ObjSerializer implements JsonSerializer<Obj> {
  public JsonElement serialize(Obj obj, Type t, JSC jsc) {
    JsonObject json = new JsonObject();
    json.addProperty("name", obj.getClass());
    json.add("value", jsc.serialize(obj, t));
    return json;
  }
}

What "should" happen is that:

A a = new A();
...
gson.toJson(a);

should have a call sequence that looks like:

ObjSerializer.serialize(a, ...)
getNextAdapter().serialize(a, ...)
ObjSerializer.serialize(subobject, ...)
getNextAdapter().serialize(subobject, ...)

That is, can we both avoid infinite recursion while also respecting nested 
registered objects' serialize mechanisms? 
http://code.google.com/p/google-gson/issues/detail?id=43#c9 seems like it 
solves this problem, but 
http://code.google.com/p/google-gson/issues/detail?id=43#c11 doesn't seem to.

Original comment by [email protected] on 6 Feb 2012 at 9:27

@GoogleCodeExporter
Copy link
Author

Yeah, you want getNextAdapter. That API was hidden in Gson 2.1 because we 
weren't sure that name was right, but its there in SVN. I'll write up an 
example and post it here...

Original comment by [email protected] on 7 Feb 2012 at 3:21

@GoogleCodeExporter
Copy link
Author

Here's a big example that demonstrates all of the moving parts of 
getNextAdapter. Drink maps to 'Obj' and MixedDrink maps to 'A' in your model. 
Note that we're using the new streaming TypeAdapter API and not the tree-based 
JsonSerializer/JsonDeserializer API. Only the new streaming API gives you 
access to the next type adapter in the chain.


package com.google.gson;

import com.google.gson.reflect.TypeToken;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
import java.io.IOException;

public class GetNextAdapterExample {

    static class Drink {
        protected final String name;

        Drink(String name) {
            this.name = name;
        }

        @Override public String toString() {
            return name;
        }
    }

    static class MixedDrink extends Drink {
        private final Drink mix;
        private final String alcohol;

        MixedDrink(String name, Drink mix, String alcohol) {
            super(name);
            this.mix = mix;
            this.alcohol = alcohol;
        }

        @Override public String toString() {
            return name + " (" + mix + "+" + alcohol + ")";
        }
    }

    public static void main(String[] args) {
        Drink orangeJuice = new Drink("Orange Juice");
        MixedDrink screwdriver = new MixedDrink("Screwdriver", orangeJuice, "Vodka");

        Gson gson = new GsonBuilder()
                .registerTypeAdapterFactory(new DrinkTypeAdapterFactory())
                .create();

        // exercise toJson
        System.out.println(gson.toJson(orangeJuice));
        System.out.println(gson.toJson(screwdriver));

        // exercise fromJson
        String s = "{'name':'Orange Juice','virgin':true}";
        String t = "{'mix':{'name':'Orange Juice','virgin':true},'alcohol':'Vodka','name':'Screwdriver'}";
        System.out.println(gson.fromJson(s, Drink.class));
        System.out.println(gson.fromJson(t, Drink.class));
    }

    static class DrinkTypeAdapterFactory implements TypeAdapterFactory {
        public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
            if (!Drink.class.isAssignableFrom(type.getRawType())) {
                return null; // this class only serializes 'Drink' and its subtypes
            }

            /*
             * Lookup type adapters to do the actual work. We use getNextAdapter
             * to avoid getting 'this' on the types that this factory supports.
             */
            final TypeAdapter<Drink> drinkAdapter
                    = gson.getNextAdapter(this, TypeToken.get(Drink.class));
            final TypeAdapter<MixedDrink> mixedDrinkAdapter
                    = gson.getNextAdapter(this, TypeToken.get(MixedDrink.class));

            /*
             * The JsonElement type adapter is always handy when we want to
             * tweak what our delegate type adapter created.
             */
            final TypeAdapter<JsonElement> elementAdapter = gson.getAdapter(JsonElement.class);

            /**
             * Now that we have some helpers, create the tweaked type adapter.
             */
            TypeAdapter<Drink> result = new TypeAdapter<Drink>() {
                @Override public void write(JsonWriter out, Drink value) throws IOException {
                    if (value instanceof MixedDrink) {
                        // write mixed drinks out normally
                        mixedDrinkAdapter.write(out, (MixedDrink) value);
                    } else {
                        /*
                         * Always add a 'virgin' attribute on non-mixed drinks.
                         * This takes three steps:
                         *  1. Get the delegate to serialize to a JsonObject,
                         *  2. Add our extra property to that JsonObject.
                         *  3. Serialize that to the stream.
                         */
                        JsonObject object = drinkAdapter.toJsonTree(value).getAsJsonObject();
                        object.add("virgin", new JsonPrimitive(true));
                        elementAdapter.write(out, object);
                    }
                }

                @Override public Drink read(JsonReader in) throws IOException {
                    /*
                     * Use the appropriate type adapter based on the contents
                     * of the stream.
                     */
                    JsonObject object = elementAdapter.read(in).getAsJsonObject();
                    if (object.has("alcohol")) {
                        return mixedDrinkAdapter.fromJsonTree(object);
                    } else {
                        return drinkAdapter.fromJsonTree(object);
                    }
                }
            }.nullSafe(); // so we don't have to check for null on the stream

            return (TypeAdapter<T>) result;
        }
    }
}

Original comment by [email protected] on 7 Feb 2012 at 4:55

@GoogleCodeExporter
Copy link
Author

Two notes about the example from the previous comment:

1) You'll need at least GSon V2.2.
2) gson.getNextAdapter was renamed to gson.getDelegateAdapter

Original comment by [email protected] on 26 Nov 2012 at 3:07

Marcono1234 pushed a commit to Marcono1234/gson that referenced this issue Apr 8, 2023
* test google#43: Changed tests to make use of assertThrows as per feedback

* Test google#43: Update JsonWriterTest#testStrictnessNull to use assertThrows

* Test google#43: Update JsonWriterTest#testStrictnessNull to use assertThrows

* test google#43: Resolve PR recommendations

* Test google#43: Mini change to TC

* Test google#43: Mini change to TC

---------

Co-authored-by: Marten Voorberg <[email protected]>
eamonnmcmanus pushed a commit that referenced this issue May 30, 2023
* Feat #6: Add strict flag to Gson and GsonBuilder

* Test #2: Add failing tests for capitalized keywords

* Feat #2: JsonReader does not read (partially) capitalized keywords if strict mode is used

* Feat #3: Added implementation and tests for JSONReader not accepting specific escape sequence representing in strict mode

* Test #3: Simplify test cases by removing unnecessary array

* Feat #3: Improve error by including the illegal character

* Feat #5: JsonReader does not allow unespaced control flow characters in strict mode

* Test #5: Test unespaced control flow characters in strict mode

* Feat #4: Disallow espaced newline character in strict mode

* Test #4: Add tests for (dis)allowing newline character depensding on strictness

* Test #5: Test case for unescaped control char in non-strict mode

* Test #2: Simplify test cases

* Feat #13: Change leniency API to Strictness enum in JsonReader, Gson, and GsonBuilder

* Feat #15: Change JsonWriter API to also use Strictness

* Test #15: Test Strictness in JsonWriter API

* Doc #15: Add and update documentation for Strictness in JsonWriter API

* refactor #12: Fixed typos and empty catch brackets in tests

* refactor #12: Resolved importing wildcards, made some lines adhere to Google java style

* #5 Add test case for unescaped control characters

* Feat #5: add new lines to make JsonReader able to detect unescaped control characters (U+0000 through U+001F) and throw exceptions.

* Feat #5: add new lines to make JsonReader able to detect unescaped control characters (U+0000 through U+001F) and throw exceptions.

* Test #11: Added two tests for testing implementation of control character handling in strict mode and moved the implementation to nextQuotedValue

* Test #11: Added two tests for testing implementation of control character handling in strict mode and moved the implementation to nextQuotedValue

---------

Co-authored-by: LMC117 <[email protected]>
Co-authored-by: Marten Voorberg <[email protected]>

* Doc #17: Add and change javadoc of public methods

* Doc #17: Update JavaDoc in JsonReader and Strictness

* Doc #17: Update JavaDoc in Gson and GsonBuilder

* Test #34: Add tests for setting strictness through GsonBuilder

* Fix: Add Fix broken test

* Fix: Invalid JavaDoc in Gson.java

* Doc #17: update outdated javadoc

* #37: Resolve more PR feedback 

* Fix #37: Resolve various PR comments

* Fix #37: Resolve various PR comments

* Refactor #35: Refactor JsonReader#peekKeyword to reduce the amount of strictness checks (#39)

* Doc #40: Update JavaDoc based on PR feedback

* Doc #40: Update old RFC in GsonBuilder documentation

* Doc #40: Fix formatting error in JavaDoc

* Doc #40: Add tests for setting strictness and lenient to JsonReaderTest

* Test #43: Changed tests to make use of assertThrows

* test #43: Changed tests to make use of assertThrows as per feedback

* Test #43: Update JsonWriterTest#testStrictnessNull to use assertThrows

* Test #43: Update JsonWriterTest#testStrictnessNull to use assertThrows

* test #43: Resolve PR recommendations

* Test #43: Mini change to TC

* Test #43: Mini change to TC

---------

Co-authored-by: Marten Voorberg <[email protected]>

* doc #46: Resolved comments in main PR

* Feat #45: Change Gson.fromJson and Gson.toJson to be strict when the provided writer/reader is strict

* Fix #45: Small type

* Update gson/src/test/java/com/google/gson/stream/JsonReaderTest.java

Co-authored-by: Marcono1234 <[email protected]>

* Fix #45: Resolve various comments by Marcono1234

* Update gson/src/main/java/com/google/gson/GsonBuilder.java

Co-authored-by: Marcono1234 <[email protected]>

* Fix #45: Resolve various comments by Marcono1234

* Fix #45: Resolve various comments by eamonmcmanus

* Strictness mode follow-up

* Update Troubleshooting.md and Gson default lenient mode documentation

* Always use GSON strictness when set.

* Rename Strictness.DEFAULT to Strictness.LEGACY_STRICT

* Update JavaDoc with new strictness functionality

* Replace default with legacy strict for JsonReader javadoc

* Add JSONReader test cases for U2028 and U2029

* Refactor JSONReader#peekKeyWord() based on @eamonmcmanus's suggestion

* Deprecate setLenient in favor of setStrictness

---------

Co-authored-by: Carl Peterson <unknown>
Co-authored-by: Gustaf Johansson <[email protected]>
Co-authored-by: gustajoh <[email protected]>
Co-authored-by: LMC117 <[email protected]>
Co-authored-by: Marcono1234 <[email protected]>
eamonnmcmanus pushed a commit that referenced this issue May 31, 2023
* Feat #6: Add strict flag to Gson and GsonBuilder

* Test #2: Add failing tests for capitalized keywords

* Feat #2: JsonReader does not read (partially) capitalized keywords if strict mode is used

* Feat #3: Added implementation and tests for JSONReader not accepting specific escape sequence representing in strict mode

* Test #3: Simplify test cases by removing unnecessary array

* Feat #3: Improve error by including the illegal character

* Feat #5: JsonReader does not allow unespaced control flow characters in strict mode

* Test #5: Test unespaced control flow characters in strict mode

* Feat #4: Disallow espaced newline character in strict mode

* Test #4: Add tests for (dis)allowing newline character depensding on strictness

* Test #5: Test case for unescaped control char in non-strict mode

* Test #2: Simplify test cases

* Feat #13: Change leniency API to Strictness enum in JsonReader, Gson, and GsonBuilder

* Feat #15: Change JsonWriter API to also use Strictness

* Test #15: Test Strictness in JsonWriter API

* Doc #15: Add and update documentation for Strictness in JsonWriter API

* refactor #12: Fixed typos and empty catch brackets in tests

* refactor #12: Resolved importing wildcards, made some lines adhere to Google java style

* #5 Add test case for unescaped control characters

* Feat #5: add new lines to make JsonReader able to detect unescaped control characters (U+0000 through U+001F) and throw exceptions.

* Feat #5: add new lines to make JsonReader able to detect unescaped control characters (U+0000 through U+001F) and throw exceptions.

* Test #11: Added two tests for testing implementation of control character handling in strict mode and moved the implementation to nextQuotedValue

* Test #11: Added two tests for testing implementation of control character handling in strict mode and moved the implementation to nextQuotedValue

---------

Co-authored-by: LMC117 <[email protected]>
Co-authored-by: Marten Voorberg <[email protected]>

* Doc #17: Add and change javadoc of public methods

* Doc #17: Update JavaDoc in JsonReader and Strictness

* Doc #17: Update JavaDoc in Gson and GsonBuilder

* Test #34: Add tests for setting strictness through GsonBuilder

* Fix: Add Fix broken test

* Fix: Invalid JavaDoc in Gson.java

* Doc #17: update outdated javadoc

* #37: Resolve more PR feedback

* Fix #37: Resolve various PR comments

* Fix #37: Resolve various PR comments

* Refactor #35: Refactor JsonReader#peekKeyword to reduce the amount of strictness checks (#39)

* Doc #40: Update JavaDoc based on PR feedback

* Doc #40: Update old RFC in GsonBuilder documentation

* Doc #40: Fix formatting error in JavaDoc

* Doc #40: Add tests for setting strictness and lenient to JsonReaderTest

* Test #43: Changed tests to make use of assertThrows

* test #43: Changed tests to make use of assertThrows as per feedback

* Test #43: Update JsonWriterTest#testStrictnessNull to use assertThrows

* Test #43: Update JsonWriterTest#testStrictnessNull to use assertThrows

* test #43: Resolve PR recommendations

* Test #43: Mini change to TC

* Test #43: Mini change to TC

---------

Co-authored-by: Marten Voorberg <[email protected]>

* doc #46: Resolved comments in main PR

* Feat #45: Change Gson.fromJson and Gson.toJson to be strict when the provided writer/reader is strict

* Fix #45: Small type

* Update gson/src/test/java/com/google/gson/stream/JsonReaderTest.java

Co-authored-by: Marcono1234 <[email protected]>

* Fix #45: Resolve various comments by Marcono1234

* Update gson/src/main/java/com/google/gson/GsonBuilder.java

Co-authored-by: Marcono1234 <[email protected]>

* Fix #45: Resolve various comments by Marcono1234

* Fix #45: Resolve various comments by eamonmcmanus

* Strictness mode follow-up

* Update Troubleshooting.md and Gson default lenient mode documentation

* Always use GSON strictness when set.

* Rename Strictness.DEFAULT to Strictness.LEGACY_STRICT

* Update JavaDoc with new strictness functionality

* Replace default with legacy strict for JsonReader javadoc

* Add JSONReader test cases for U2028 and U2029

* Refactor JSONReader#peekKeyWord() based on @eamonmcmanus's suggestion

* Deprecate setLenient in favor of setStrictness

---------

Co-authored-by: Carl Peterson <unknown>
Co-authored-by: Gustaf Johansson <[email protected]>
Co-authored-by: gustajoh <[email protected]>
Co-authored-by: LMC117 <[email protected]>
Co-authored-by: Marcono1234 <[email protected]>
eamonnmcmanus added a commit that referenced this issue Jul 30, 2023
* Strict mode for JSON parsing (#2323)

* Feat #6: Add strict flag to Gson and GsonBuilder

* Test #2: Add failing tests for capitalized keywords

* Feat #2: JsonReader does not read (partially) capitalized keywords if strict mode is used

* Feat #3: Added implementation and tests for JSONReader not accepting specific escape sequence representing in strict mode

* Test #3: Simplify test cases by removing unnecessary array

* Feat #3: Improve error by including the illegal character

* Feat #5: JsonReader does not allow unespaced control flow characters in strict mode

* Test #5: Test unespaced control flow characters in strict mode

* Feat #4: Disallow espaced newline character in strict mode

* Test #4: Add tests for (dis)allowing newline character depensding on strictness

* Test #5: Test case for unescaped control char in non-strict mode

* Test #2: Simplify test cases

* Feat #13: Change leniency API to Strictness enum in JsonReader, Gson, and GsonBuilder

* Feat #15: Change JsonWriter API to also use Strictness

* Test #15: Test Strictness in JsonWriter API

* Doc #15: Add and update documentation for Strictness in JsonWriter API

* refactor #12: Fixed typos and empty catch brackets in tests

* refactor #12: Resolved importing wildcards, made some lines adhere to Google java style

* #5 Add test case for unescaped control characters

* Feat #5: add new lines to make JsonReader able to detect unescaped control characters (U+0000 through U+001F) and throw exceptions.

* Feat #5: add new lines to make JsonReader able to detect unescaped control characters (U+0000 through U+001F) and throw exceptions.

* Test #11: Added two tests for testing implementation of control character handling in strict mode and moved the implementation to nextQuotedValue

* Test #11: Added two tests for testing implementation of control character handling in strict mode and moved the implementation to nextQuotedValue

---------

Co-authored-by: LMC117 <[email protected]>
Co-authored-by: Marten Voorberg <[email protected]>

* Doc #17: Add and change javadoc of public methods

* Doc #17: Update JavaDoc in JsonReader and Strictness

* Doc #17: Update JavaDoc in Gson and GsonBuilder

* Test #34: Add tests for setting strictness through GsonBuilder

* Fix: Add Fix broken test

* Fix: Invalid JavaDoc in Gson.java

* Doc #17: update outdated javadoc

* #37: Resolve more PR feedback 

* Fix #37: Resolve various PR comments

* Fix #37: Resolve various PR comments

* Refactor #35: Refactor JsonReader#peekKeyword to reduce the amount of strictness checks (#39)

* Doc #40: Update JavaDoc based on PR feedback

* Doc #40: Update old RFC in GsonBuilder documentation

* Doc #40: Fix formatting error in JavaDoc

* Doc #40: Add tests for setting strictness and lenient to JsonReaderTest

* Test #43: Changed tests to make use of assertThrows

* test #43: Changed tests to make use of assertThrows as per feedback

* Test #43: Update JsonWriterTest#testStrictnessNull to use assertThrows

* Test #43: Update JsonWriterTest#testStrictnessNull to use assertThrows

* test #43: Resolve PR recommendations

* Test #43: Mini change to TC

* Test #43: Mini change to TC

---------

Co-authored-by: Marten Voorberg <[email protected]>

* doc #46: Resolved comments in main PR

* Feat #45: Change Gson.fromJson and Gson.toJson to be strict when the provided writer/reader is strict

* Fix #45: Small type

* Update gson/src/test/java/com/google/gson/stream/JsonReaderTest.java

Co-authored-by: Marcono1234 <[email protected]>

* Fix #45: Resolve various comments by Marcono1234

* Update gson/src/main/java/com/google/gson/GsonBuilder.java

Co-authored-by: Marcono1234 <[email protected]>

* Fix #45: Resolve various comments by Marcono1234

* Fix #45: Resolve various comments by eamonmcmanus

* Strictness mode follow-up

* Update Troubleshooting.md and Gson default lenient mode documentation

* Always use GSON strictness when set.

* Rename Strictness.DEFAULT to Strictness.LEGACY_STRICT

* Update JavaDoc with new strictness functionality

* Replace default with legacy strict for JsonReader javadoc

* Add JSONReader test cases for U2028 and U2029

* Refactor JSONReader#peekKeyWord() based on @eamonmcmanus's suggestion

* Deprecate setLenient in favor of setStrictness

---------

Co-authored-by: Carl Peterson <unknown>
Co-authored-by: Gustaf Johansson <[email protected]>
Co-authored-by: gustajoh <[email protected]>
Co-authored-by: LMC117 <[email protected]>
Co-authored-by: Marcono1234 <[email protected]>

* Strictness follow-up (#2408)

* Strictness mode follow-up

- Remove mentions of `null` Gson strictness; this is an implementation detail
- Fix incorrect / outdated documentation
- Reduce links to RFC; if there is already a link to it in a previous sentence
  don't link to it again
- Extend and update tests
- Minor punctuation changes in documentation for consistency

* Deprecate `setLenient` methods

* `strictness2` fixes & improvements (#2456)

* Adjust ProGuard default rules and shrinking tests (#2420)

* Adjust ProGuard default rules and shrinking tests

* Adjust comment

* Add shrinking test for class without no-args constructor; improve docs

* Improve Unsafe mention in Troubleshooting Guide

* Improve comment for `-if class *`

* Bump com.google.guava:guava from 32.0.1-jre to 32.1.1-jre (#2444)

Bumps [com.google.guava:guava](https://github.com/google/guava) from 32.0.1-jre to 32.1.1-jre.
- [Release notes](https://github.com/google/guava/releases)
- [Commits](https://github.com/google/guava/commits)

---
updated-dependencies:
- dependency-name: com.google.guava:guava
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump com.google.guava:guava-testlib from 32.0.1-jre to 32.1.1-jre (#2443)

Bumps [com.google.guava:guava-testlib](https://github.com/google/guava) from 32.0.1-jre to 32.1.1-jre.
- [Release notes](https://github.com/google/guava/releases)
- [Commits](https://github.com/google/guava/commits)

---
updated-dependencies:
- dependency-name: com.google.guava:guava-testlib
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Support non-generic type for `TypeToken.getParameterized` for legacy reasons (#2447)

This partially restores the behavior before a589ef2,
except that back then for a non-generic type a bogus `TypeToken(ParameterizedType)`
was created, whereas now a `TypeToken(Class)` is created instead.

* Fixed Typo in GsonBuilder.java (#2449)

* Make date-formatting tests less fragile with regular expressions. (#2450)

* Make date-formatting tests less fragile with regular expressions.

This is not great. We should really ensure that formatted dates are the same
regardless of JDK version. There is code that attempts to do that but it is not
really effective. So for now we fudge around the differences by using regular
expressions to paper over the differences.

* Temporarily add test-debugging code.

* Another attempt at debugging a test failure.

* Fix pattern in assertion.

* Modification in test cases (#2454)

* Fixed Typo in GsonBuilder.java

* Suggestions on Test cases

* Modified test cases using assertThrows method (JUnit)

* Update gson/src/test/java/com/google/gson/JsonArrayAsListTest.java

Co-authored-by: Marcono1234 <[email protected]>

* Update gson/src/test/java/com/google/gson/GsonTest.java

Co-authored-by: Marcono1234 <[email protected]>

* Update gson/src/test/java/com/google/gson/JsonArrayAsListTest.java

Co-authored-by: Marcono1234 <[email protected]>

* Update gson/src/test/java/com/google/gson/JsonStreamParserTest.java

Co-authored-by: Marcono1234 <[email protected]>

* Update gson/src/test/java/com/google/gson/JsonStreamParserTest.java

Co-authored-by: Marcono1234 <[email protected]>

* Update gson/src/test/java/com/google/gson/JsonStreamParserTest.java

Co-authored-by: Marcono1234 <[email protected]>

* Update gson/src/test/java/com/google/gson/ToNumberPolicyTest.java

Co-authored-by: Marcono1234 <[email protected]>

* Update gson/src/test/java/com/google/gson/TypeAdapterTest.java

Co-authored-by: Marcono1234 <[email protected]>

* Update gson/src/test/java/com/google/gson/TypeAdapterTest.java

Co-authored-by: Marcono1234 <[email protected]>

* Update gson/src/test/java/com/google/gson/ToNumberPolicyTest.java

Co-authored-by: Marcono1234 <[email protected]>

* Update gson/src/test/java/com/google/gson/ToNumberPolicyTest.java

Co-authored-by: Marcono1234 <[email protected]>

---------

Co-authored-by: Marcono1234 <[email protected]>

* Minor follow-up changes

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: elevne <[email protected]>
Co-authored-by: Éamonn McManus <[email protected]>
Co-authored-by: Wonil <[email protected]>

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: Marten <[email protected]>
Co-authored-by: Gustaf Johansson <[email protected]>
Co-authored-by: gustajoh <[email protected]>
Co-authored-by: LMC117 <[email protected]>
Co-authored-by: Marcono1234 <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: elevne <[email protected]>
Co-authored-by: Wonil <[email protected]>
tibor-universe pushed a commit to getuniverse/gson that referenced this issue Sep 14, 2024
…e#2437)

* Strict mode for JSON parsing (google#2323)

* Feat #6: Add strict flag to Gson and GsonBuilder

* Test #2: Add failing tests for capitalized keywords

* Feat #2: JsonReader does not read (partially) capitalized keywords if strict mode is used

* Feat #3: Added implementation and tests for JSONReader not accepting specific escape sequence representing in strict mode

* Test #3: Simplify test cases by removing unnecessary array

* Feat #3: Improve error by including the illegal character

* Feat #5: JsonReader does not allow unespaced control flow characters in strict mode

* Test #5: Test unespaced control flow characters in strict mode

* Feat #4: Disallow espaced newline character in strict mode

* Test #4: Add tests for (dis)allowing newline character depensding on strictness

* Test #5: Test case for unescaped control char in non-strict mode

* Test #2: Simplify test cases

* Feat #13: Change leniency API to Strictness enum in JsonReader, Gson, and GsonBuilder

* Feat #15: Change JsonWriter API to also use Strictness

* Test #15: Test Strictness in JsonWriter API

* Doc #15: Add and update documentation for Strictness in JsonWriter API

* refactor #12: Fixed typos and empty catch brackets in tests

* refactor #12: Resolved importing wildcards, made some lines adhere to Google java style

* #5 Add test case for unescaped control characters

* Feat #5: add new lines to make JsonReader able to detect unescaped control characters (U+0000 through U+001F) and throw exceptions.

* Feat #5: add new lines to make JsonReader able to detect unescaped control characters (U+0000 through U+001F) and throw exceptions.

* Test #11: Added two tests for testing implementation of control character handling in strict mode and moved the implementation to nextQuotedValue

* Test #11: Added two tests for testing implementation of control character handling in strict mode and moved the implementation to nextQuotedValue

---------

Co-authored-by: LMC117 <[email protected]>
Co-authored-by: Marten Voorberg <[email protected]>

* Doc #17: Add and change javadoc of public methods

* Doc #17: Update JavaDoc in JsonReader and Strictness

* Doc #17: Update JavaDoc in Gson and GsonBuilder

* Test google#34: Add tests for setting strictness through GsonBuilder

* Fix: Add Fix broken test

* Fix: Invalid JavaDoc in Gson.java

* Doc #17: update outdated javadoc

* google#37: Resolve more PR feedback

* Fix google#37: Resolve various PR comments

* Fix google#37: Resolve various PR comments

* Refactor google#35: Refactor JsonReader#peekKeyword to reduce the amount of strictness checks (google#39)

* Doc google#40: Update JavaDoc based on PR feedback

* Doc google#40: Update old RFC in GsonBuilder documentation

* Doc google#40: Fix formatting error in JavaDoc

* Doc google#40: Add tests for setting strictness and lenient to JsonReaderTest

* Test google#43: Changed tests to make use of assertThrows

* test google#43: Changed tests to make use of assertThrows as per feedback

* Test google#43: Update JsonWriterTest#testStrictnessNull to use assertThrows

* Test google#43: Update JsonWriterTest#testStrictnessNull to use assertThrows

* test google#43: Resolve PR recommendations

* Test google#43: Mini change to TC

* Test google#43: Mini change to TC

---------

Co-authored-by: Marten Voorberg <[email protected]>

* doc google#46: Resolved comments in main PR

* Feat google#45: Change Gson.fromJson and Gson.toJson to be strict when the provided writer/reader is strict

* Fix google#45: Small type

* Update gson/src/test/java/com/google/gson/stream/JsonReaderTest.java

Co-authored-by: Marcono1234 <[email protected]>

* Fix google#45: Resolve various comments by Marcono1234

* Update gson/src/main/java/com/google/gson/GsonBuilder.java

Co-authored-by: Marcono1234 <[email protected]>

* Fix google#45: Resolve various comments by Marcono1234

* Fix google#45: Resolve various comments by eamonmcmanus

* Strictness mode follow-up

* Update Troubleshooting.md and Gson default lenient mode documentation

* Always use GSON strictness when set.

* Rename Strictness.DEFAULT to Strictness.LEGACY_STRICT

* Update JavaDoc with new strictness functionality

* Replace default with legacy strict for JsonReader javadoc

* Add JSONReader test cases for U2028 and U2029

* Refactor JSONReader#peekKeyWord() based on @eamonmcmanus's suggestion

* Deprecate setLenient in favor of setStrictness

---------

Co-authored-by: Carl Peterson <unknown>
Co-authored-by: Gustaf Johansson <[email protected]>
Co-authored-by: gustajoh <[email protected]>
Co-authored-by: LMC117 <[email protected]>
Co-authored-by: Marcono1234 <[email protected]>

* Strictness follow-up (google#2408)

* Strictness mode follow-up

- Remove mentions of `null` Gson strictness; this is an implementation detail
- Fix incorrect / outdated documentation
- Reduce links to RFC; if there is already a link to it in a previous sentence
  don't link to it again
- Extend and update tests
- Minor punctuation changes in documentation for consistency

* Deprecate `setLenient` methods

* `strictness2` fixes & improvements (google#2456)

* Adjust ProGuard default rules and shrinking tests (google#2420)

* Adjust ProGuard default rules and shrinking tests

* Adjust comment

* Add shrinking test for class without no-args constructor; improve docs

* Improve Unsafe mention in Troubleshooting Guide

* Improve comment for `-if class *`

* Bump com.google.guava:guava from 32.0.1-jre to 32.1.1-jre (google#2444)

Bumps [com.google.guava:guava](https://github.com/google/guava) from 32.0.1-jre to 32.1.1-jre.
- [Release notes](https://github.com/google/guava/releases)
- [Commits](https://github.com/google/guava/commits)

---
updated-dependencies:
- dependency-name: com.google.guava:guava
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump com.google.guava:guava-testlib from 32.0.1-jre to 32.1.1-jre (google#2443)

Bumps [com.google.guava:guava-testlib](https://github.com/google/guava) from 32.0.1-jre to 32.1.1-jre.
- [Release notes](https://github.com/google/guava/releases)
- [Commits](https://github.com/google/guava/commits)

---
updated-dependencies:
- dependency-name: com.google.guava:guava-testlib
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Support non-generic type for `TypeToken.getParameterized` for legacy reasons (google#2447)

This partially restores the behavior before a589ef2,
except that back then for a non-generic type a bogus `TypeToken(ParameterizedType)`
was created, whereas now a `TypeToken(Class)` is created instead.

* Fixed Typo in GsonBuilder.java (google#2449)

* Make date-formatting tests less fragile with regular expressions. (google#2450)

* Make date-formatting tests less fragile with regular expressions.

This is not great. We should really ensure that formatted dates are the same
regardless of JDK version. There is code that attempts to do that but it is not
really effective. So for now we fudge around the differences by using regular
expressions to paper over the differences.

* Temporarily add test-debugging code.

* Another attempt at debugging a test failure.

* Fix pattern in assertion.

* Modification in test cases (google#2454)

* Fixed Typo in GsonBuilder.java

* Suggestions on Test cases

* Modified test cases using assertThrows method (JUnit)

* Update gson/src/test/java/com/google/gson/JsonArrayAsListTest.java

Co-authored-by: Marcono1234 <[email protected]>

* Update gson/src/test/java/com/google/gson/GsonTest.java

Co-authored-by: Marcono1234 <[email protected]>

* Update gson/src/test/java/com/google/gson/JsonArrayAsListTest.java

Co-authored-by: Marcono1234 <[email protected]>

* Update gson/src/test/java/com/google/gson/JsonStreamParserTest.java

Co-authored-by: Marcono1234 <[email protected]>

* Update gson/src/test/java/com/google/gson/JsonStreamParserTest.java

Co-authored-by: Marcono1234 <[email protected]>

* Update gson/src/test/java/com/google/gson/JsonStreamParserTest.java

Co-authored-by: Marcono1234 <[email protected]>

* Update gson/src/test/java/com/google/gson/ToNumberPolicyTest.java

Co-authored-by: Marcono1234 <[email protected]>

* Update gson/src/test/java/com/google/gson/TypeAdapterTest.java

Co-authored-by: Marcono1234 <[email protected]>

* Update gson/src/test/java/com/google/gson/TypeAdapterTest.java

Co-authored-by: Marcono1234 <[email protected]>

* Update gson/src/test/java/com/google/gson/ToNumberPolicyTest.java

Co-authored-by: Marcono1234 <[email protected]>

* Update gson/src/test/java/com/google/gson/ToNumberPolicyTest.java

Co-authored-by: Marcono1234 <[email protected]>

---------

Co-authored-by: Marcono1234 <[email protected]>

* Minor follow-up changes

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: elevne <[email protected]>
Co-authored-by: Éamonn McManus <[email protected]>
Co-authored-by: Wonil <[email protected]>

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: Marten <[email protected]>
Co-authored-by: Gustaf Johansson <[email protected]>
Co-authored-by: gustajoh <[email protected]>
Co-authored-by: LMC117 <[email protected]>
Co-authored-by: Marcono1234 <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: elevne <[email protected]>
Co-authored-by: Wonil <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant