Permalink
Browse files

Merge branch 'gmaster'

Conflicts:
	CHANGELOG.md
	LICENSE
	README.md
	examples/android-proguard-example/proguard.cfg
	examples/android-proguard-example/src/com/google/gson/examples/android/model/LineItem.java
	extras/pom.xml
	extras/src/main/java/com/google/gson/typeadapters/RuntimeTypeAdapterFactory.java
	gson/pom.xml
	gson/src/main/java/com/google/gson/Gson.java
	gson/src/main/java/com/google/gson/GsonBuilder.java
	gson/src/main/java/com/google/gson/internal/ConstructorConstructor.java
	gson/src/main/java/com/google/gson/internal/bind/ArrayTypeAdapter.java
	gson/src/main/java/com/google/gson/internal/bind/CollectionTypeAdapterFactory.java
	gson/src/main/java/com/google/gson/internal/bind/MapTypeAdapterFactory.java
	gson/src/main/java/com/google/gson/internal/bind/ReflectiveTypeAdapterFactory.java
	gson/src/main/java/com/google/gson/internal/bind/TreeTypeAdapter.java
	gson/src/main/java/com/google/gson/internal/bind/TypeAdapterRuntimeTypeWrapper.java
	gson/src/main/java/com/google/gson/internal/bind/TypeAdapters.java
	gson/src/main/java/com/google/gson/stream/JsonReader.java
	gson/src/test/java/com/google/gson/functional/DefaultTypeAdaptersTest.java
	gson/src/test/java/com/google/gson/functional/JsonAdapterAnnotationOnClassesTest.java
	gson/src/test/java/com/google/gson/functional/JsonAdapterAnnotationOnFieldsTest.java
	pom.xml
	proto/src/main/java/com/google/gson/protobuf/ProtoTypeAdapter.java
	proto/src/test/java/com/google/gson/protobuf/functional/ProtosWithPrimitiveTypesTest.java
  • Loading branch information...
amogilev committed Jan 8, 2017
2 parents 8448a1a + e9ead40 commit f6f550f74fa8e93fb3ad872b4d1d8ceff1298a6e
Showing with 2,379 additions and 747 deletions.
  1. +76 −0 extras/src/main/java/com/google/gson/typeadapters/PostConstructAdapterFactory.java
  2. +50 −0 extras/src/test/java/com/google/gson/typeadapters/PostConstructAdapterFactoryTest.java
  3. +14 −0 gson/bnd.bnd
  4. +19 −203 gson/pom.xml
  5. +9 −10 gson/src/main/java/com/google/gson/DefaultDateTypeAdapter.java
  6. +1 −1 gson/src/main/java/com/google/gson/FieldAttributes.java
  7. +8 −8 gson/src/main/java/com/google/gson/FieldNamingPolicy.java
  8. +121 −34 gson/src/main/java/com/google/gson/Gson.java
  9. +36 −12 gson/src/main/java/com/google/gson/GsonBuilder.java
  10. +1 −1 gson/src/main/java/com/google/gson/JsonArray.java
  11. +9 −0 gson/src/main/java/com/google/gson/JsonObject.java
  12. +2 −2 gson/src/main/java/com/google/gson/LongSerializationPolicy.java
  13. +2 −0 gson/src/main/java/com/google/gson/annotations/Expose.java
  14. +3 −0 gson/src/main/java/com/google/gson/annotations/JsonAdapter.java
  15. +2 −0 gson/src/main/java/com/google/gson/annotations/SerializedName.java
  16. +2 −0 gson/src/main/java/com/google/gson/annotations/Since.java
  17. +2 −0 gson/src/main/java/com/google/gson/annotations/Until.java
  18. +5 −5 gson/src/main/java/com/google/gson/internal/$Gson$Types.java
  19. +27 −15 gson/src/main/java/com/google/gson/internal/ConstructorConstructor.java
  20. +1 −1 gson/src/main/java/com/google/gson/internal/Excluder.java
  21. +3 −0 gson/src/main/java/com/google/gson/internal/LinkedHashTreeMap.java
  22. +4 −1 gson/src/main/java/com/google/gson/internal/LinkedTreeMap.java
  23. +1 −2 gson/src/main/java/com/google/gson/internal/Streams.java
  24. +19 −0 gson/src/main/java/com/google/gson/internal/UnsafeAllocator.java
  25. +1 −1 gson/src/main/java/com/google/gson/internal/bind/ArrayTypeAdapter.java
  26. +1 −0 gson/src/main/java/com/google/gson/internal/bind/CollectionTypeAdapterFactory.java
  27. +6 −11 gson/src/main/java/com/google/gson/internal/bind/DateTypeAdapter.java
  28. +31 −16 gson/src/main/java/com/google/gson/internal/bind/JsonAdapterAnnotationTypeAdapterFactory.java
  29. +114 −24 gson/src/main/java/com/google/gson/internal/bind/JsonTreeReader.java
  30. +8 −0 gson/src/main/java/com/google/gson/internal/bind/JsonTreeWriter.java
  31. +2 −2 gson/src/main/java/com/google/gson/internal/bind/MapTypeAdapterFactory.java
  32. +2 −2 gson/src/main/java/com/google/gson/internal/bind/ObjectTypeAdapter.java
  33. +40 −24 gson/src/main/java/com/google/gson/internal/bind/ReflectiveTypeAdapterFactory.java
  34. +1 −1 gson/src/main/java/com/google/gson/internal/bind/SqlDateTypeAdapter.java
  35. +1 −1 gson/src/main/java/com/google/gson/internal/bind/TimeTypeAdapter.java
  36. +33 −9 gson/src/main/java/com/google/gson/{ → internal/bind}/TreeTypeAdapter.java
  37. +6 −5 gson/src/main/java/com/google/gson/internal/bind/TypeAdapterRuntimeTypeWrapper.java
  38. +111 −20 gson/src/main/java/com/google/gson/internal/bind/TypeAdapters.java
  39. +352 −0 gson/src/main/java/com/google/gson/internal/bind/util/ISO8601Utils.java
  40. +15 −0 gson/src/main/java/com/google/gson/reflect/TypeToken.java
  41. +43 −63 gson/src/main/java/com/google/gson/stream/JsonReader.java
  42. +27 −19 gson/src/main/java/com/google/gson/stream/JsonWriter.java
  43. +9 −0 gson/src/test/java/com/google/gson/DefaultDateTypeAdapterTest.java
  44. +54 −0 gson/src/test/java/com/google/gson/GsonTest.java
  45. +4 −5 gson/src/test/java/com/google/gson/GsonTypeAdapterTest.java
  46. +14 −0 gson/src/test/java/com/google/gson/JsonObjectTest.java
  47. +2 −0 gson/src/test/java/com/google/gson/MockExclusionStrategy.java
  48. +4 −4 gson/src/test/java/com/google/gson/ParameterizedTypeFixtures.java
  49. +1 −1 gson/src/test/java/com/google/gson/ParameterizedTypeTest.java
  50. +8 −5 gson/src/test/java/com/google/gson/common/TestTypes.java
  51. +48 −12 gson/src/test/java/com/google/gson/functional/CollectionTest.java
  52. +7 −2 gson/src/test/java/com/google/gson/functional/CustomDeserializerTest.java
  53. +25 −16 gson/src/test/java/com/google/gson/functional/CustomTypeAdaptersTest.java
  54. +12 −2 gson/src/test/java/com/google/gson/functional/DefaultTypeAdaptersTest.java
  55. +3 −1 gson/src/test/java/com/google/gson/functional/DelegateTypeAdapterTest.java
  56. +2 −2 gson/src/test/java/com/google/gson/functional/EnumTest.java
  57. +5 −5 gson/src/test/java/com/google/gson/functional/ExclusionStrategyFunctionalTest.java
  58. +1 −1 gson/src/test/java/com/google/gson/functional/ExposeFieldsTest.java
  59. +5 −5 gson/src/test/java/com/google/gson/functional/InstanceCreatorTest.java
  60. +110 −0 gson/src/test/java/com/google/gson/functional/JavaUtilConcurrentAtomicTest.java
  61. +62 −0 gson/src/test/java/com/google/gson/functional/JavaUtilTest.java
  62. +24 −1 gson/src/test/java/com/google/gson/functional/JsonAdapterAnnotationOnClassesTest.java
  63. +105 −4 gson/src/test/java/com/google/gson/functional/JsonAdapterAnnotationOnFieldsTest.java
  64. +164 −0 gson/src/test/java/com/google/gson/functional/JsonAdapterSerializerDeserializerTest.java
  65. +46 −0 gson/src/test/java/com/google/gson/functional/LeniencyTest.java
  66. +80 −8 gson/src/test/java/com/google/gson/functional/MapTest.java
  67. +3 −2 gson/src/test/java/com/google/gson/functional/NamingPolicyTest.java
  68. +3 −3 gson/src/test/java/com/google/gson/functional/NullObjectAndFieldTest.java
  69. +2 −2 gson/src/test/java/com/google/gson/functional/RuntimeTypeAdapterFactoryFunctionalTest.java
  70. +1 −1 gson/src/test/java/com/google/gson/functional/SerializedNameTest.java
  71. +2 −0 gson/src/test/java/com/google/gson/functional/TreeTypeAdaptersTest.java
  72. +2 −0 gson/src/test/java/com/google/gson/functional/TypeAdapterPrecedenceTest.java
  73. +4 −4 gson/src/test/java/com/google/gson/functional/TypeHierarchyAdapterTest.java
  74. +1 −1 gson/src/test/java/com/google/gson/functional/UncategorizedTest.java
  75. +74 −0 gson/src/test/java/com/google/gson/internal/UnsafeAllocatorInstantiationTest.java
  76. +23 −0 gson/src/test/java/com/google/gson/reflect/TypeTokenTest.java
  77. +62 −0 gson/src/test/java/com/google/gson/regression/JsonAdapterNullSafeTest.java
  78. +63 −24 gson/src/test/java/com/google/gson/stream/JsonReaderPathTest.java
  79. +42 −42 gson/src/test/java/com/google/gson/stream/JsonReaderTest.java
  80. +46 −2 gson/src/test/java/com/google/gson/stream/JsonWriterTest.java
  81. +44 −99 pom.xml
  82. +1 −0 proto/.gitignore
@@ -0,0 +1,76 @@
/*
* Copyright (C) 2016 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.typeadapters;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import javax.annotation.PostConstruct;
import com.google.gson.Gson;
import com.google.gson.TypeAdapter;
import com.google.gson.TypeAdapterFactory;
import com.google.gson.reflect.TypeToken;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
public class PostConstructAdapterFactory implements TypeAdapterFactory {
// copied from https://gist.github.com/swankjesse/20df26adaf639ed7fd160f145a0b661a
@Override
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
for (Class<?> t = type.getRawType(); t != Object.class; t = t.getSuperclass()) {
for (Method m : t.getDeclaredMethods()) {
if (m.isAnnotationPresent(PostConstruct.class)) {
m.setAccessible(true);
TypeAdapter<T> delegate = gson.getDelegateAdapter(this, type);
return new PostConstructAdapter<T>(delegate, m);
}
}
}
return null;
}
final static class PostConstructAdapter<T> extends TypeAdapter<T> {
private final TypeAdapter<T> delegate;
private final Method method;
public PostConstructAdapter(TypeAdapter<T> delegate, Method method) {
this.delegate = delegate;
this.method = method;
}
@Override public T read(JsonReader in) throws IOException {
T result = delegate.read(in);
if (result != null) {
try {
method.invoke(result);
} catch (IllegalAccessException e) {
throw new AssertionError();
} catch (InvocationTargetException e) {
if (e.getCause() instanceof RuntimeException) throw (RuntimeException) e.getCause();
throw new RuntimeException(e.getCause());
}
}
return result;
}
@Override public void write(JsonWriter out, T value) throws IOException {
delegate.write(out, value);
}
}
}
@@ -0,0 +1,50 @@
/*
* Copyright (C) 2016 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.typeadapters;
import javax.annotation.PostConstruct;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import junit.framework.TestCase;
public class PostConstructAdapterFactoryTest extends TestCase {
public void test() throws Exception {
Gson gson = new GsonBuilder()
.registerTypeAdapterFactory(new PostConstructAdapterFactory())
.create();
gson.fromJson("{\"bread\": \"white\", \"cheese\": \"cheddar\"}", Sandwich.class);
try {
gson.fromJson("{\"bread\": \"cheesey bread\", \"cheese\": \"swiss\"}", Sandwich.class);
fail();
} catch (IllegalArgumentException expected) {
assertEquals("too cheesey", expected.getMessage());
}
}
static class Sandwich {
String bread;
String cheese;
@PostConstruct void validate() {
if (bread.equals("cheesey bread") && cheese != null) {
throw new IllegalArgumentException("too cheesey");
}
}
}
}
View
@@ -0,0 +1,14 @@
Bundle-SymbolicName: com.google.gson
Bundle-Name: ${project.name}
Bundle-Description: ${project.description}
Bundle-Vendor: Google Gson Project
Bundle-ContactAddress: ${project.parent.url}
Bundle-RequiredExecutionEnvironment: J2SE-1.5, JavaSE-1.6, JavaSE-1.7, JavaSE-1.8
-removeheaders: Private-Package
-exportcontents:\
com.google.gson,\
com.google.gson.annotations,\
com.google.gson.reflect,\
com.google.gson.stream
View
@@ -1,232 +1,48 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.gilecode.yagson</groupId>
<parent>
<groupId>com.gilecode.yagson</groupId>
<artifactId>yagson-parent</artifactId>
<version>0.2-SNAPSHOT</version>
</parent>
<artifactId>yagson</artifactId>
<packaging>jar</packaging>
<version>0.2-SNAPSHOT</version>
<inceptionYear>2015</inceptionYear>
<name>YaGson</name>
<url>https://github.com/amogilev/yagson</url>
<description>YaGson Java-JSON-Java binding library</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<licenses>
<license>
<name>The Apache Software License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
<distribution>repo</distribution>
</license>
</licenses>
<scm>
<connection>scm:git:https://github.com/amogilev/yagson.git</connection>
<developerConnection>scm:git:https://github.com/amogilev/yagson.git</developerConnection>
<url>https://github.com/amogilev/yagson</url>
</scm>
<distributionManagement>
<snapshotRepository>
<id>ossrh</id>
<name>Sonatype Nexus Snapshots</name>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
</snapshotRepository>
<repository>
<id>ossrh</id>
<name>Nexus Release Repository</name>
<url>http://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.2</version>
<scope>test</scope>
</dependency>
</dependencies>
<profiles>
<!-- Activate PGP signing only when performing a release -->
<profile>
<id>release-sign-artifacts</id>
<activation>
<property>
<name>performRelease</name>
<value>true</value>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>doclint-java8-disable</id>
<activation>
<jdk>[1.8,)</jdk>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<additionalparam>-Xdoclint:none</additionalparam>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<build>
<defaultGoal>package</defaultGoal>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
<includePackageNames>com.gilecode.yagson:com.google.gson</includePackageNames>
<excludePackageNames>com.google.gson.internal:com.google.gson.internal.bind</excludePackageNames>
<links>
<link>http://docs.oracle.com/javase/6/docs/api/</link>
</links>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
<configuration>
<archive>
<addMavenDescriptor>false</addMavenDescriptor>
<manifestEntries>
<Bundle-RequiredExecutionEnvironment>JavaSE-1.6, JavaSE-1.7, JavaSE-1.8</Bundle-RequiredExecutionEnvironment>
<Export-Package><![CDATA[com.gilecode.yagson;version=${project.version}, com.gilecode.yagson.adapters;version=${project.version}, com.gilecode.yagson.refs;version=${project.version}, com.gilecode.yagson.refs.impl;version=${project.version}, com.gilecode.yagson.strategy;version=${project.version}, com.gilecode.yagson.types;version=${project.version}]]></Export-Package>
<Bundle-Version>${project.version}</Bundle-Version>
<Bundle-ContactAddress>https://github.com/amogilev/yagson</Bundle-ContactAddress>
<Bundle-Name>${project.name}</Bundle-Name>
<Bundle-Description>${project.description}</Bundle-Description>
<Bundle-ClassPath>.</Bundle-ClassPath>
<Bundle-ManifestVersion>2</Bundle-ManifestVersion>
<Bundle-SymbolicName>com.gilecode.yagson</Bundle-SymbolicName>
</manifestEntries>
</archive>
</configuration>
</plugin>
<plugin>
<!-- TODO(inder): add manifest entry for maven group, artifact, and classifier ids -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>attach-sources</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
<configuration>
<archive>
<manifestEntries>
<Eclipse-SourceBundle>com.gilecode.yagson;version="${project.version}"</Eclipse-SourceBundle>
<Bundle-SymbolicName>com.gilecode.yagson.source</Bundle-SymbolicName>
<Bundle-ManifestVersion>2</Bundle-ManifestVersion>
<Bundle-Version>${project.version}</Bundle-Version>
</manifestEntries>
</archive>
</configuration>
</plugin>
<plugin>
<!-- TODO(inder): add manifest entry for maven group, artifact, and classifier ids -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.10.3</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
<configuration>
<includePackageNames>com.gilecode.yagson:com.google.gson</includePackageNames>
<excludePackageNames>com.google.gson.internal:com.google.gson.internal.bind</excludePackageNames>
<links>
<link>http://docs.oracle.com/javase/1.6.0/docs/api/</link>
</links>
<version>true</version>
<show>protected</show>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.5.5</version>
<configuration>
<descriptor>assembly-descriptor.xml</descriptor>
<finalName>yagson-${project.version}</finalName>
<outputDirectory>target/dist</outputDirectory>
<workDirectory>target/assembly/work</workDirectory>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.3</version>
<groupId>biz.aQute.bnd</groupId>
<artifactId>bnd-maven-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
<goal>bnd-process</goal>
</goals>
<configuration>
<relocations>
<relocation>
<pattern>com.google.gson</pattern>
<shadedPattern>com.gilecode.yagson.com.google.gson</shadedPattern>
</relocation>
</relocations>
<createSourcesJar>true</createSourcesJar>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.7</version>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
<autoReleaseAfterClose>false</autoReleaseAfterClose>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
</plugins>
</build>
<developers>
Oops, something went wrong.

0 comments on commit f6f550f

Please sign in to comment.