Comments (2)
Yes can confirm this; it looks like this was indeed introduced by 3e3266c (by accident):
There is only JsonWriter.value(long)
, so the adapters for all other integral primitive types (byte
, short
, int
) actually call value(long)
.
Sorry for that. Maybe it would make sense to (partially) revert that commit.
It seems AtomicInteger
is affected as well, but it's adapter always behaved this way, that a Long
instead of the AtomicInteger
is stored in the JsonPrimitive
. However, this might be a good thing since it is mutable and might cause confusing behavior if it was stored in JsonPrimitive
.
from gson.
Ok, so the potential issues with the current implementation are:
- Conversion to
Long
might be unexpected (especially when implicitly usingJsonTreeWriter
as described in your issue here)
Might depend on the use case whether that is a problem for user code. - Conversion to
Long
instead of keeping for example theByte
orInteger
might take up more memory
This might be especially noticeable when you have a lot ofJsonPrimitive
s containing them. But maybe that also depends on the JVM object layout for these boxed objects. Maybe aLong
is not actually that much larger than anInteger
, despitelong
being larger thanint
(?), but I haven't investigated that yet.
Reverting 3e3266c (or at least parts of it) would also revert narrowing numeric conversion, e.g. 1.5f
-> (byte) 1
, see #2156. Though that was originally reported by me, and I am not sure if / how many users were actually negatively affected by that behavior.
That could be solved again by performing the narrowing conversion, but then boxing as Number
again and then call JsonWriter#value(Number)
instead of JsonWriter#value(long)
, but performance-wise this will likely not be ideal.
Maybe JsonWriter#value(Number)
could also be refactored to first check using a new isTrustedIntegralNumberType
, to avoid redundant string.equals("-Infinity")
checks in these cases. Though it would have to be verified if that actually makes a noticeable performance difference.
So am I currently not sure what the best approach here would be.
@eamonnmcmanus, what do you think?
from gson.
Related Issues (20)
- Assertion is Missed to Validate testWriterCloseIsIdempotent Test for JsonWriter's Idempotency
- Assertion is Missed to Validate `testWriterCloseIsIdempotent` Test for JsonWriter's Idempotency HOT 2
- Split `testWriteHtmlSafe` into Two Separate Test Cases for Improved Test Granularity HOT 2
- GSON deserialization fails with ClassCastException: Cannot cast com.google.gson.internal.LinkedTreeMap to androidx.collection.ArrayMap HOT 1
- OSS-Fuzz issue 67620 HOT 3
- Edge case where R8 removes the TypeToken's generic type (while consuming the library's recently updated proguard rules)
- `JsonReader#beginObject` should throw checked exceptions, instead throws runtime `IllegalStateException`. HOT 2
- Serialization failure at index 0 and 1 in camel case field naming convention HOT 2
- [2.11.0] error_prone_annotations dependency HOT 5
- The module declaration in version 2.11.0 is not visible HOT 11
- errorprone cannot be considered optional HOT 4
- Can't read multiline string in JSON5 HOT 3
- Performance regressions from 2.10.1 to 2.11.0 on R8 minification task HOT 2
- Implement fallback if class `java.security.AccessController` does not exist HOT 5
- JDK21 toJson failure HOT 6
- Make com.google.gson.JsonElement Serializeable HOT 1
- Custom Gson, singleton mode, deserialization in multiple coroutines, resulting in crash HOT 2
- error HOT 4
- Read `json_name` from protobuf field annotations for serialization and deserialization
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gson.