Skip to content
Commits on Source (15)
......@@ -13,4 +13,8 @@ release.properties
*.iws
classes
.gradle
local.properties
build
.DS_Store
language: java
jdk:
- oraclejdk7
- openjdk7
- oraclejdk8
install: mvn -f gson install -DskipTests=true
......
Change Log
==========
## Version 2.8.4
_2018-05-01_ [GitHub Diff](https://github.com/google/gson/compare/gson-parent-2.8.3...gson-parent-2.8.4)
* Added a new FieldNamingPolicy, `LOWER_CASE_WITH_DOTS` that mapps JSON name `someFieldName` to `some.field.name`
* Fixed issue https://github.com/google/gson/issues/1305 by removing compile/runtime dependency on `sun.misc.Unsafe`
## Version 2.8.3
_2018-04-27_ [GitHub Diff](https://github.com/google/gson/compare/gson-parent-2.8.2...gson-parent-2.8.3)
* Added a new API, `GsonBuilder.newBuilder()` that clones the current builder
* Preserving DateFormatter behavior on JDK 9
* Numerous other bugfixes
## Version 2.8.2
_2017-09-19_ [GitHub Diff](https://github.com/google/gson/compare/gson-parent-2.8.1...gson-parent-2.8.2)
* Introduced a new API, `JsonElement.deepCopy()`
......
......@@ -17,20 +17,35 @@ There are a few open-source projects that can convert Java objects to JSON. Howe
* Support arbitrarily complex objects (with deep inheritance hierarchies and extensive use of generic types)
### Gson Download and Maven
* To use Gson in Android
```gradle
dependencies {
implementation 'com.google.code.gson:gson:2.8.4'
}
```
* [Gson Download](https://maven-badges.herokuapp.com/maven-central/com.google.code.gson/gson) downloads at Maven Central
* For Maven check "Dependency Information" tab, on the left side.
* To use Gson with Maven
```xml
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.4</version>
</dependency>
```
### Gson Documentation
* Gson [API](http://www.javadoc.io/doc/com.google.code.gson/gson): Javadocs for the current Gson release
* Gson [user guide](https://github.com/google/gson/blob/master/UserGuide.md): This guide contains examples on how to use Gson in your code.
* Gson [Roadmap](https://github.com/google/gson/blob/master/CHANGELOG.md): Details of changes in the recent versions
* Gson [design document](https://github.com/google/gson/blob/master/GsonDesignDocument.md): This document discusses issues we faced while designing Gson. It also include a comparison of Gson with other Java libraries that can be used for Json conversion
* Gson [design document](https://github.com/google/gson/blob/master/GsonDesignDocument.md): This document discusses issues we faced while designing Gson. It also includes a comparison of Gson with other Java libraries that can be used for Json conversion
Please use the [google-gson Google group](http://groups.google.com/group/google-gson) to discuss Gson, or to post questions.
### Gson-related Content Created by Third Parties
* [Gson Tutorial](http://www.studytrails.com/java/json/java-google-json-introduction.jsp) by `StudyTrails`
* [Gson Tutorial Series](https://futurestud.io/tutorials/gson-getting-started-with-java-json-serialization-deserialization) by `Future Studio`
* [Gson API Report](https://abi-laboratory.pro/java/tracker/timeline/gson/)
### License
......
......@@ -3,49 +3,16 @@
The following is a step-by-step procedure for releasing a new version of Google-Gson.
1. Go through all open bugs and identify which will be fixed in this release. Mark all others with an appropriate release tag. Identify duplicates, and close the bugs that will never be fixed. Fix all bugs for the release, and mark them fixed.
1. (obsolete step) Edit [`pom.xml`](pom.xml) and update the versions listed for Export-Package to the target version. Also add any new Java packages that have been introduced in Gson.
1. Ensure all changelists are code-reviewed and have +1
1. (obsolete step) Ensure that your `~/.m2/settings.xml` is configured properly (see steps below)
1. `cd gson` to the parent directory; ensure there are no open files and all changes are committed.
1. Run `mvn release:clean`
1. Do a dry run: `mvn release:prepare -DdryRun=true`
1. Start the release: `mvn release:prepare`
* Answer questions: usually the defaults are fine.
* This will do a full build, change version from `-SNAPSHOT` to the released version, commit and create the tags. It will then change the version to `-SNAPSHOT` for the next release.
1. Ensure you have defined `sonatype-nexus-staging` in your Maven `settings.xml` and run:
```bash
mvn -s /home/<username>/.m2/settings.xml release:perform
```
1. [Log in to Nexus repository manager](https://oss.sonatype.org/index.html#welcome) at Sonatype and close the staging repository for Gson. If you run into an error regarding missing signatures, you need to manually upload the artifacts using `mvn gpg:sign-and-deploy-file` for Gson binary, source and Javadoc jars.
```bash
cp -r ~/.m2/repository/com/google/code/gson/gson/1.7.2 /tmp
cd /tmp/1.7.2
mvn gpg:sign-and-deploy-file \
-Durl=https://oss.sonatype.org/service/local/staging/deploy/maven2/ \
-DrepositoryId=sonatype-nexus-staging \
-DpomFile=gson-1.7.2.pom \
-Dfile=gson-1.7.2-javadoc.jar \
-Dclassifier=javadoc
mvn gpg:sign-and-deploy-file \
-Durl=https://oss.sonatype.org/service/local/staging/deploy/maven2/ \
-DrepositoryId=sonatype-nexus-staging \
-DpomFile=gson-1.7.2.pom \
-Dfile=gson-1.7.2-sources.jar \
-Dclassifier=sources
mvn gpg:sign-and-deploy-file \
-Durl=https://oss.sonatype.org/service/local/staging/deploy/maven2/ \
-DrepositoryId=sonatype-nexus-staging \
-DpomFile=gson-1.7.2.pom \
-Dfile=gson-1.7.2.jar
```
1. Close the Gson repository. Download and sanity check all downloads. Do not skip this step! Once you release the staging repository, there is no going back. It will get synced with Maven central and you will not be able to update or delete anything. Your only recourse will be to release a new version of Gson and hope that no one uses the old one.
1. Complete the release: `mvn release:perform`
1. [Log in to Nexus repository manager](https://oss.sonatype.org/index.html#welcome) at Sonatype and close the staging repository for Gson.
1. Download and sanity check all downloads. Do not skip this step! Once you release the staging repository, there is no going back. It will get synced with Maven central and you will not be able to update or delete anything. Your only recourse will be to release a new version of Gson and hope that no one uses the old one.
1. Release the staging repository for Gson. Gson will now get synced to Maven central with-in the next hour. For issues consult [Sonatype Guide](https://docs.sonatype.org/display/Repository/Sonatype+OSS+Maven+Repository+Usage+Guide#SonatypeOSSMavenRepositoryUsageGuide-8.ReleaseIt).
1. Update the version in the [Using Gson with Maven2 page](https://github.com/google/gson/blob/master/UserGuide.md#TOC-Gson-With-Maven)
......@@ -58,16 +25,16 @@ The following is a step-by-step procedure for releasing a new version of Google-
This section was borrowed heavily from [Doclava release process](http://code.google.com/p/doclava/wiki/ProcessRelease).
1. Install/Configure GPG following this [guide](http://www.sonatype.com/people/2010/01/how-to-generate-pgp-signatures-with-maven/).
2. [Create encrypted passwords](http://maven.apache.org/guides/mini/guide-encryption.html).
3. Create `~/.m2/settings.xml` similar to as described in [Doclava release process](https://code.google.com/p/doclava/wiki/ProcessRelease).
4. Now for deploying a snapshot repository, use `mvn deploy`.
1. [Create encrypted passwords](http://maven.apache.org/guides/mini/guide-encryption.html).
1. Create `~/.m2/settings.xml` similar to as described in [Doclava release process](https://code.google.com/p/doclava/wiki/ProcessRelease).
1. Now for deploying a snapshot repository, use `mvn deploy`.
## Getting Maven Publishing Privileges
Based on [Gson group thread](https://groups.google.com/d/topic/google-gson/DHWJHVFpIBg/discussion):
1. [Sign up for a Sonatype account](https://docs.sonatype.org/display/Repository/Sonatype+OSS+Maven+Repository+Usage+Guide) following instructions under (2) on that page
2. Ask one of the existing members of the repository to create a JIRA ticket (Step 3 of above document) to add you to the publisher list.
1. Ask one of the existing members of the repository to create a JIRA ticket (Step 3 of above document) to add you to the publisher list.
## Running Benchmarks or Tests on Android
......
......@@ -5,6 +5,7 @@
3. [Gson Performance and Scalability](#TOC-Gson-Performance-and-Scalability)
4. [Gson Users](#TOC-Gson-Users)
5. [Using Gson](#TOC-Using-Gson)
* [Using Gson with Gradle/Android](#TOC-Gson-With-Gradle)
* [Using Gson with Maven](#TOC-Gson-With-Maven)
* [Primitives Examples](#TOC-Primitives-Examples)
* [Object Examples](#TOC-Object-Examples)
......@@ -70,6 +71,12 @@ The primary class to use is [`Gson`](gson/src/main/java/com/google/gson/Gson.jav
The Gson instance does not maintain any state while invoking Json operations. So, you are free to reuse the same object for multiple Json serialization and deserialization operations.
## <a name="TOC-Gson-With-Gradle"></a>Using Gson with Gradle/Android
```
dependencies {
compile 'com.google.code.gson:gson:2.8.4'
}
```
## <a name="TOC-Gson-With-Maven"></a>Using Gson with Maven
To use Gson with Maven2/3, you can use the Gson version available in Maven Central by adding the following dependency:
......@@ -79,7 +86,7 @@ To use Gson with Maven2/3, you can use the Gson version available in Maven Centr
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.0</version>
<version>2.8.4</version>
<scope>compile</scope>
</dependency>
</dependencies>
......@@ -137,14 +144,14 @@ BagOfPrimitives obj2 = gson.fromJson(json, BagOfPrimitives.class);
#### <a name="TOC-Finer-Points-with-Objects"></a>**Finer Points with Objects**
* It is perfectly fine (and recommended) to use private fields
* It is perfectly fine (and recommended) to use private fields.
* There is no need to use any annotations to indicate a field is to be included for serialization and deserialization. All fields in the current class (and from all super classes) are included by default.
* If a field is marked transient, (by default) it is ignored and not included in the JSON serialization or deserialization.
* This implementation handles nulls correctly
* While serializing, a null field is skipped from the output
* While deserializing, a missing entry in JSON results in setting the corresponding field in the object to null
* If a field is _synthetic_, it is ignored and not included in JSON serialization or deserialization
* Fields corresponding to the outer classes in inner classes, anonymous classes, and local classes are ignored and not included in serialization or deserialization
* This implementation handles nulls correctly.
* While serializing, a null field is omitted from the output.
* While deserializing, a missing entry in JSON results in setting the corresponding field in the object to its default value: null for object types, zero for numeric types, and false for booleans.
* If a field is _synthetic_, it is ignored and not included in JSON serialization or deserialization.
* Fields corresponding to the outer classes in inner classes, anonymous classes, and local classes are ignored and not included in serialization or deserialization.
### <a name="TOC-Nested-Classes-including-Inner-Classes-"></a>Nested Classes (including Inner Classes)
......
buildscript {
repositories {
mavenCentral()
}
}
allprojects {
repositories {
mavenCentral()
}
}
libgoogle-gson-java (2.8.5-1) unstable; urgency=medium
* New upstream release
- Removed the Java 9 patches (fixed upstream)
- Replaced templating-maven-plugin with sed
* Ignore the broken tests to work around the build failure with Java 11
(Closes: #912433)
* Restored the parent of gson/pom.xml to inherit the build settings
* Updated the watch file for the recent releases
* Standards-Version updated to 4.2.1
* Exclude the Gradle wrapper from the upstream tarball
* Use salsa.debian.org Vcs-* URLs
-- Emmanuel Bourg <ebourg@apache.org> Thu, 08 Nov 2018 12:04:52 +0100
libgoogle-gson-java (2.8.2-1) unstable; urgency=medium
* Team upload.
......
gson/src/main/java/com/google/gson/internal/GsonBuildConfig.java
......@@ -2,23 +2,25 @@ Source: libgoogle-gson-java
Priority: optional
Section: java
Maintainer: Debian Java Maintainers <pkg-java-maintainers@lists.alioth.debian.org>
Uploaders: Jakub Adam <jakub.adam@ktknet.cz>, Emmanuel Bourg <ebourg@apache.org>
Build-Depends: debhelper (>= 11),
Uploaders:
Jakub Adam <jakub.adam@ktknet.cz>,
Emmanuel Bourg <ebourg@apache.org>
Build-Depends:
debhelper (>= 11),
default-jdk,
javahelper,
junit4,
libmaven-bundle-plugin-java,
libmaven-javadoc-plugin-java,
maven-debian-helper
Standards-Version: 4.1.3
Vcs-Git: https://anonscm.debian.org/git/pkg-java/libgoogle-gson-java.git
Vcs-Browser: https://anonscm.debian.org/cgit/pkg-java/libgoogle-gson-java.git
Standards-Version: 4.2.1
Vcs-Git: https://salsa.debian.org/java-team/libgoogle-gson-java.git
Vcs-Browser: https://salsa.debian.org/java-team/libgoogle-gson-java
Homepage: https://github.com/google/gson
Package: libgoogle-gson-java
Architecture: all
Depends: ${maven:Depends},
${misc:Depends}
Depends: ${maven:Depends}, ${misc:Depends}
Recommends: ${maven:OptionalDepends}
Suggests: libgoogle-gson-java-doc
Description: Converts Java objects into their JSON representation
......
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: Google Gson
Source: https://github.com/google/gson/releases
Files-Excluded: *.jar
gradlew*
Upstream-Authors:
Inderjeet Singh, Trymph Inc.
Joel Leitch, Google Inc.
......
......@@ -27,7 +27,7 @@
#
codegen/pom.xml --ignore
extras/pom.xml --ignore
gson/pom.xml --no-parent --java-lib
gson/pom.xml --java-lib
metrics/pom.xml --ignore
proto/pom.xml --ignore
pom.xml --no-parent
......@@ -6,3 +6,4 @@ org.apache.maven.plugins maven-source-plugin * * * *
org.sonatype.oss oss-parent * * * *
biz.aQute.bnd bnd-maven-plugin * * * *
org.apache.maven.plugins maven-jar-plugin * * * *
org.codehaus.mojo templating-maven-plugin * * * *
project.build.sourceEncoding=utf-8
maven.test.failure.ignore=true
This diff is collapsed.
From 8445689e4d1159298179580b4e260ed23bb2b9bc Mon Sep 17 00:00:00 2001
From: Andrey Mogilev <amogilev@gmail.com>
Date: Thu, 4 Jan 2018 02:08:50 +0700
Subject: [PATCH] Java 9 support: use Unsafe-based reflection in Java 9+
(#1218)
* Java 9 support: use Unsafe-based reflection in Java 9+
fixes "illegal reflective access" warnings and exceptions
* fix Codacy warnings
* improve code quality based on PR review
* improve code quality based on PR review
* fix Codacy warning
* improve code quality based on PR review
* inlined createReflectionAccessor method
---
.../gson/internal/ConstructorConstructor.java | 4 +-
.../bind/ReflectiveTypeAdapterFactory.java | 4 +-
.../reflect/PreJava9ReflectionAccessor.java | 36 ++++++++++++
.../gson/internal/reflect/ReflectionAccessor.java | 54 ++++++++++++++++++
.../internal/reflect/UnsafeReflectionAccessor.java | 64 ++++++++++++++++++++++
.../java/com/google/gson/reflect/package-info.java | 2 +-
6 files changed, 161 insertions(+), 3 deletions(-)
create mode 100644 gson/src/main/java/com/google/gson/internal/reflect/PreJava9ReflectionAccessor.java
create mode 100644 gson/src/main/java/com/google/gson/internal/reflect/ReflectionAccessor.java
create mode 100644 gson/src/main/java/com/google/gson/internal/reflect/UnsafeReflectionAccessor.java
diff --git a/gson/src/main/java/com/google/gson/internal/ConstructorConstructor.java b/gson/src/main/java/com/google/gson/internal/ConstructorConstructor.java
index 6d1e7c967..5fab46010 100644
--- a/gson/src/main/java/com/google/gson/internal/ConstructorConstructor.java
+++ b/gson/src/main/java/com/google/gson/internal/ConstructorConstructor.java
@@ -40,6 +40,7 @@
import com.google.gson.InstanceCreator;
import com.google.gson.JsonIOException;
+import com.google.gson.internal.reflect.ReflectionAccessor;
import com.google.gson.reflect.TypeToken;
/**
@@ -47,6 +48,7 @@
*/
public final class ConstructorConstructor {
private final Map<Type, InstanceCreator<?>> instanceCreators;
+ private final ReflectionAccessor accessor = ReflectionAccessor.getInstance();
public ConstructorConstructor(Map<Type, InstanceCreator<?>> instanceCreators) {
this.instanceCreators = instanceCreators;
@@ -98,7 +100,7 @@ public ConstructorConstructor(Map<Type, InstanceCreator<?>> instanceCreators) {
try {
final Constructor<? super T> constructor = rawType.getDeclaredConstructor();
if (!constructor.isAccessible()) {
- constructor.setAccessible(true);
+ accessor.makeAccessible(constructor);
}
return new ObjectConstructor<T>() {
@SuppressWarnings("unchecked") // T is the same raw type as is requested
diff --git a/gson/src/main/java/com/google/gson/internal/bind/ReflectiveTypeAdapterFactory.java b/gson/src/main/java/com/google/gson/internal/bind/ReflectiveTypeAdapterFactory.java
index 42798d059..777e7dee3 100644
--- a/gson/src/main/java/com/google/gson/internal/bind/ReflectiveTypeAdapterFactory.java
+++ b/gson/src/main/java/com/google/gson/internal/bind/ReflectiveTypeAdapterFactory.java
@@ -28,6 +28,7 @@
import com.google.gson.internal.Excluder;
import com.google.gson.internal.ObjectConstructor;
import com.google.gson.internal.Primitives;
+import com.google.gson.internal.reflect.ReflectionAccessor;
import com.google.gson.reflect.TypeToken;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonToken;
@@ -49,6 +50,7 @@
private final FieldNamingStrategy fieldNamingPolicy;
private final Excluder excluder;
private final JsonAdapterAnnotationTypeAdapterFactory jsonAdapterFactory;
+ private final ReflectionAccessor accessor = ReflectionAccessor.getInstance();
public ReflectiveTypeAdapterFactory(ConstructorConstructor constructorConstructor,
FieldNamingStrategy fieldNamingPolicy, Excluder excluder,
@@ -154,7 +156,7 @@ static boolean excludeField(Field f, boolean serialize, Excluder excluder) {
if (!serialize && !deserialize) {
continue;
}
- field.setAccessible(true);
+ accessor.makeAccessible(field);
Type fieldType = $Gson$Types.resolve(type.getType(), raw, field.getGenericType());
List<String> fieldNames = getFieldNames(field);
BoundField previous = null;
diff --git a/gson/src/main/java/com/google/gson/internal/reflect/PreJava9ReflectionAccessor.java b/gson/src/main/java/com/google/gson/internal/reflect/PreJava9ReflectionAccessor.java
new file mode 100644
index 000000000..2f006517e
--- /dev/null
+++ b/gson/src/main/java/com/google/gson/internal/reflect/PreJava9ReflectionAccessor.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2017 The Gson authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.google.gson.internal.reflect;
+
+import java.lang.reflect.AccessibleObject;
+
+/**
+ * A basic implementation of {@link ReflectionAccessor} which is suitable for Java 8 and below.
+ * <p>
+ * This implementation just calls {@link AccessibleObject#setAccessible(boolean) setAccessible(true)}, which worked
+ * fine before Java 9.
+ */
+final class PreJava9ReflectionAccessor extends ReflectionAccessor {
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void makeAccessible(AccessibleObject ao) {
+ ao.setAccessible(true);
+ }
+
+}
diff --git a/gson/src/main/java/com/google/gson/internal/reflect/ReflectionAccessor.java b/gson/src/main/java/com/google/gson/internal/reflect/ReflectionAccessor.java
new file mode 100644
index 000000000..42230d254
--- /dev/null
+++ b/gson/src/main/java/com/google/gson/internal/reflect/ReflectionAccessor.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2017 The Gson authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.google.gson.internal.reflect;
+
+import com.google.gson.util.VersionUtils;
+
+import java.lang.reflect.AccessibleObject;
+
+/**
+ * Provides a replacement for {@link AccessibleObject#setAccessible(boolean)}, which may be used to
+ * avoid reflective access issues appeared in Java 9, like {@link java.lang.reflect.InaccessibleObjectException}
+ * thrown or warnings like
+ * <pre>
+ * WARNING: An illegal reflective access operation has occurred
+ * WARNING: Illegal reflective access by ...
+ * </pre>
+ * <p/>
+ * Works both for Java 9 and earlier Java versions.
+ */
+public abstract class ReflectionAccessor {
+
+ // the singleton instance, use getInstance() to obtain
+ private static final ReflectionAccessor instance = VersionUtils.getMajorJavaVersion() < 9 ? new PreJava9ReflectionAccessor() : new UnsafeReflectionAccessor();
+
+ /**
+ * Does the same as {@code ao.setAccessible(true)}, but never throws
+ * {@link java.lang.reflect.InaccessibleObjectException}
+ */
+ public abstract void makeAccessible(AccessibleObject ao);
+
+ /**
+ * Obtains a {@link ReflectionAccessor} instance suitable for the current Java version.
+ * <p>
+ * You may need one a reflective operation in your code throws {@link java.lang.reflect.InaccessibleObjectException}.
+ * In such a case, use {@link ReflectionAccessor#makeAccessible(AccessibleObject)} on a field, method or constructor
+ * (instead of basic {@link AccessibleObject#setAccessible(boolean)}).
+ */
+ public static ReflectionAccessor getInstance() {
+ return instance;
+ }
+}
diff --git a/gson/src/main/java/com/google/gson/internal/reflect/UnsafeReflectionAccessor.java b/gson/src/main/java/com/google/gson/internal/reflect/UnsafeReflectionAccessor.java
new file mode 100644
index 000000000..5bc59bd8e
--- /dev/null
+++ b/gson/src/main/java/com/google/gson/internal/reflect/UnsafeReflectionAccessor.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2017 The Gson authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.google.gson.internal.reflect;
+
+import sun.misc.Unsafe;
+
+import java.lang.reflect.AccessibleObject;
+import java.lang.reflect.Field;
+
+/**
+ * An implementation of {@link ReflectionAccessor} based on {@link Unsafe}.
+ * <p>
+ * NOTE: This implementation is designed for Java 9. Although it should work with earlier Java releases, it is better to
+ * use {@link PreJava9ReflectionAccessor} for them.
+ */
+final class UnsafeReflectionAccessor extends ReflectionAccessor {
+
+ private final Unsafe theUnsafe = getUnsafeInstance();
+ private final Field overrideField = getOverrideField();
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void makeAccessible(AccessibleObject ao) {
+ if (theUnsafe != null && overrideField != null) {
+ long overrideOffset = theUnsafe.objectFieldOffset(overrideField);
+ theUnsafe.putBoolean(ao, overrideOffset, true);
+ }
+ }
+
+ private static Unsafe getUnsafeInstance() {
+ try {
+ Field unsafeField = Unsafe.class.getDeclaredField("theUnsafe");
+ unsafeField.setAccessible(true);
+ return (Unsafe) unsafeField.get(null);
+ } catch (Exception e) {
+ e.printStackTrace();
+ return null;
+ }
+ }
+
+ private static Field getOverrideField() {
+ try {
+ return AccessibleObject.class.getDeclaredField("override");
+ } catch (NoSuchFieldException e) {
+ e.printStackTrace();
+ return null;
+ }
+ }
+}
diff --git a/gson/src/main/java/com/google/gson/reflect/package-info.java b/gson/src/main/java/com/google/gson/reflect/package-info.java
index e666c4311..5e43ee9fc 100644
--- a/gson/src/main/java/com/google/gson/reflect/package-info.java
+++ b/gson/src/main/java/com/google/gson/reflect/package-info.java
@@ -1,6 +1,6 @@
/**
* This package provides utility classes for finding type information for generic types.
- *
+ *
* @author Inderjeet Singh, Joel Leitch
*/
package com.google.gson.reflect;
\ No newline at end of file
java9-dateformat.patch
java9-reflection.patch
#!/usr/bin/make -f
include /usr/share/dpkg/pkg-info.mk
%:
dh $@ --with javahelper --buildsystem=maven
get-orig-source:
uscan --force-download --download-current-version --rename
override_dh_auto_build:
cp -Rvp gson/src/main/java-templates/* gson/src/main/java/
sed -i s/\$$\{project.version\}/$(DEB_VERSION_UPSTREAM)/ gson/src/main/java/com/google/gson/internal/GsonBuildConfig.java
dh_auto_build
version=3
https://github.com/google/gson/tags .*/gson-([\d\.]+).tar.gz
version=4
opts="repack,compression=xz" \
https://github.com/google/gson/tags .*/gson(?:-parent)?-([\d\.]+).tar.gz
File mode changed from 100755 to 100644