Permalink
Browse files

add/update license headers

  • Loading branch information...
amogilev committed Sep 24, 2016
1 parent 28966b3 commit c7dbae81856e2c68ea81f849523c061d6ca5d41b
Showing with 1,431 additions and 193 deletions.
  1. +2 −1 LICENSE
  2. +17 −2 gson/src/main/java/com/gilecode/yagson/ReadContext.java
  3. +15 −0 gson/src/main/java/com/gilecode/yagson/WriteContext.java
  4. +15 −0 gson/src/main/java/com/gilecode/yagson/YaGson.java
  5. +15 −0 gson/src/main/java/com/gilecode/yagson/YaGsonBuilder.java
  6. +18 −2 gson/src/main/java/com/{google/gson/internal/bind → gilecode/yagson/adapters}/AdapterUtils.java
  7. +100 −0 gson/src/main/java/com/gilecode/yagson/adapters/DefaultTypeAdapterRuntimeWrapper.java
  8. +31 −0 gson/src/main/java/com/gilecode/yagson/adapters/DelegatingTypeAdapter.java
  9. +22 −0 gson/src/main/java/com/gilecode/yagson/adapters/HasField.java
  10. +55 −0 gson/src/main/java/com/gilecode/yagson/adapters/SimpleTypeAdapter.java
  11. +15 −0 gson/src/main/java/com/gilecode/yagson/adapters/ThreadTypesAdapterFactory.java
  12. +4 −3 ...{google/gson/internal/bind → gilecode/yagson/adapters}/TypeAdviceReadingSimpleAdapterWrapper.java
  13. +16 −1 ...a/com/{google/gson/internal/bind → gilecode/yagson/adapters}/TypeAdvisableComplexTypeAdapter.java
  14. +4 −3 ...om/{google/gson/internal/bind → gilecode/yagson/adapters}/TypeInfoEmittingTypeAdapterWrapper.java
  15. +15 −0 gson/src/main/java/com/gilecode/yagson/refs/HashReferencePlaceholder.java
  16. +15 −0 gson/src/main/java/com/gilecode/yagson/refs/PathElementProducer.java
  17. +15 −0 gson/src/main/java/com/gilecode/yagson/refs/PlaceholderUse.java
  18. +15 −0 gson/src/main/java/com/gilecode/yagson/refs/ReferencePlaceholder.java
  19. +15 −0 gson/src/main/java/com/gilecode/yagson/refs/References.java
  20. +15 −0 gson/src/main/java/com/gilecode/yagson/refs/ReferencesContextFactory.java
  21. +15 −0 gson/src/main/java/com/gilecode/yagson/refs/ReferencesPolicy.java
  22. +16 −1 gson/src/main/java/com/gilecode/yagson/refs/ReferencesReadContext.java
  23. +15 −0 gson/src/main/java/com/gilecode/yagson/refs/ReferencesWriteContext.java
  24. +15 −0 gson/src/main/java/com/gilecode/yagson/refs/impl/FieldReferencePlaceholder.java
  25. +16 −1 gson/src/main/java/com/gilecode/yagson/refs/impl/MapPlaceholderUse.java
  26. +16 −1 gson/src/main/java/com/gilecode/yagson/refs/impl/PlaceholderUtils.java
  27. +16 −1 gson/src/main/java/com/gilecode/yagson/refs/impl/ReferencesAllDuplicatesModeContext.java
  28. +15 −0 gson/src/main/java/com/gilecode/yagson/refs/impl/ReferencesAllDuplicatesModeContextFactory.java
  29. +15 −0 gson/src/main/java/com/gilecode/yagson/refs/impl/ReferencesCircularAndSiblingsContextFactory.java
  30. +15 −0 gson/src/main/java/com/gilecode/yagson/refs/impl/ReferencesCircularAndSiblingsModeContext.java
  31. +15 −0 gson/src/main/java/com/gilecode/yagson/refs/impl/ReferencesCircularOnlyModeContext.java
  32. +15 −0 gson/src/main/java/com/gilecode/yagson/refs/impl/ReferencesCircularOnlyModeContextFactory.java
  33. +15 −0 gson/src/main/java/com/gilecode/yagson/refs/impl/ReferencesNoneModeContext.java
  34. +15 −0 gson/src/main/java/com/gilecode/yagson/refs/impl/ReferencesNoneModeContextFactory.java
  35. +15 −0 gson/src/main/java/com/gilecode/yagson/strategy/ExcludeClassesAssignableTo.java
  36. +15 −0 gson/src/main/java/com/gilecode/yagson/strategy/ExcludeFieldsByDeclaringClasses.java
  37. +15 −0 gson/src/main/java/com/gilecode/yagson/strategy/ExcludeFieldsInClassesByNames.java
  38. +15 −0 gson/src/main/java/com/gilecode/yagson/strategy/ExcludeTransientFieldsInClassByNames.java
  39. +15 −0 gson/src/main/java/com/gilecode/yagson/strategy/ExcludeTransientFieldsInDeclaringClassByNames.java
  40. +15 −0 gson/src/main/java/com/gilecode/yagson/strategy/TransientFieldExclusionStrategy.java
  41. +15 −0 gson/src/main/java/com/gilecode/yagson/types/COWSubListPostReadProcessor.java
  42. +15 −0 gson/src/main/java/com/gilecode/yagson/types/ConstructingObjectProvider.java
  43. +15 −0 gson/src/main/java/com/gilecode/yagson/types/EmitTypeInfoPredicate.java
  44. +15 −0 gson/src/main/java/com/gilecode/yagson/types/ExistingObjectProvider.java
  45. +15 −0 gson/src/main/java/com/gilecode/yagson/types/FieldInfo.java
  46. +15 −0 gson/src/main/java/com/gilecode/yagson/types/ObjectProvider.java
  47. +15 −0 gson/src/main/java/com/gilecode/yagson/types/PostAllocateProcessor.java
  48. +15 −0 gson/src/main/java/com/gilecode/yagson/types/PostReadProcessor.java
  49. +15 −0 gson/src/main/java/com/gilecode/yagson/types/SetFromMapPostReadProcessor.java
  50. +15 −0 gson/src/main/java/com/gilecode/yagson/types/TypeInfoPolicy.java
  51. +16 −1 gson/src/main/java/com/gilecode/yagson/types/TypeUtils.java
  52. +0 −7 gson/src/main/java/com/google/gson/FutureTypeAdapterAccessor.java
  53. +3 −0 gson/src/main/java/com/google/gson/Gson.java
  54. +1 −0 gson/src/main/java/com/google/gson/GsonBuilder.java
  55. +1 −0 gson/src/main/java/com/google/gson/JsonParser.java
  56. +1 −0 gson/src/main/java/com/google/gson/JsonStreamParser.java
  57. +0 −39 gson/src/main/java/com/google/gson/SimpleTypeAdapter.java
  58. +1 −0 gson/src/main/java/com/google/gson/TreeTypeAdapter.java
  59. +1 −0 gson/src/main/java/com/google/gson/TypeAdapter.java
  60. +1 −0 gson/src/main/java/com/google/gson/internal/$Gson$Types.java
  61. +1 −0 gson/src/main/java/com/google/gson/internal/ConstructorConstructor.java
  62. +1 −0 gson/src/main/java/com/google/gson/internal/Excluder.java
  63. +1 −0 gson/src/main/java/com/google/gson/internal/JsonReaderInternalAccess.java
  64. +1 −0 gson/src/main/java/com/google/gson/internal/Streams.java
  65. +2 −0 gson/src/main/java/com/google/gson/internal/bind/ArrayTypeAdapter.java
  66. +3 −0 gson/src/main/java/com/google/gson/internal/bind/CollectionTypeAdapterFactory.java
  67. +2 −1 gson/src/main/java/com/google/gson/internal/bind/DateTypeAdapter.java
  68. +0 −98 gson/src/main/java/com/google/gson/internal/bind/DefaultTypeAdapterRuntimeWrapper.java
  69. +0 −16 gson/src/main/java/com/google/gson/internal/bind/DelegatingTypeAdapter.java
  70. +0 −7 gson/src/main/java/com/google/gson/internal/bind/HasField.java
  71. +1 −0 gson/src/main/java/com/google/gson/internal/bind/JsonTreeReader.java
  72. +3 −0 gson/src/main/java/com/google/gson/internal/bind/MapTypeAdapterFactory.java
  73. +1 −0 gson/src/main/java/com/google/gson/internal/bind/ObjectTypeAdapter.java
  74. +4 −0 gson/src/main/java/com/google/gson/internal/bind/ReflectiveTypeAdapterFactory.java
  75. +2 −1 gson/src/main/java/com/google/gson/internal/bind/SqlDateTypeAdapter.java
  76. +2 −1 gson/src/main/java/com/google/gson/internal/bind/TimeTypeAdapter.java
  77. +3 −1 gson/src/main/java/com/google/gson/internal/bind/TypeAdapterRuntimeTypeWrapper.java
  78. +2 −0 gson/src/main/java/com/google/gson/internal/bind/TypeAdapters.java
  79. +1 −0 gson/src/main/java/com/google/gson/stream/JsonReader.java
  80. +15 −0 gson/src/test/java/com/gilecode/yagson/TestGsonBugFixes.java
  81. +15 −0 gson/src/test/java/com/gilecode/yagson/TestTypeUtils.java
  82. +15 −0 gson/src/test/java/com/gilecode/yagson/tests/TestDuplicateFields.java
  83. +15 −0 gson/src/test/java/com/gilecode/yagson/tests/TestEnumCollections.java
  84. +15 −0 gson/src/test/java/com/gilecode/yagson/tests/TestExcludedClasses.java
  85. +15 −0 gson/src/test/java/com/gilecode/yagson/tests/TestInnerClass.java
  86. +15 −0 gson/src/test/java/com/gilecode/yagson/tests/TestInstantiation.java
  87. +15 −0 gson/src/test/java/com/gilecode/yagson/tests/TestMixedTypesCollections.java
  88. +15 −0 gson/src/test/java/com/gilecode/yagson/tests/TestReferences.java
  89. +15 −0 gson/src/test/java/com/gilecode/yagson/tests/TestRootType.java
  90. +15 −0 gson/src/test/java/com/gilecode/yagson/tests/TestSelfContainingCollections.java
  91. +15 −0 gson/src/test/java/com/gilecode/yagson/tests/TestThreads.java
  92. +15 −0 gson/src/test/java/com/gilecode/yagson/tests/TestTypeInfo.java
  93. +15 −0 gson/src/test/java/com/gilecode/yagson/tests/TestVariousCollections.java
  94. +15 −0 gson/src/test/java/com/gilecode/yagson/tests/TestVariousLists.java
  95. +15 −0 gson/src/test/java/com/gilecode/yagson/tests/TestVariousMaps.java
  96. +15 −0 gson/src/test/java/com/gilecode/yagson/tests/TestVariousQueues.java
  97. +15 −0 gson/src/test/java/com/gilecode/yagson/tests/TestVariousSets.java
  98. +15 −0 gson/src/test/java/com/gilecode/yagson/tests/TestWeakReferences.java
  99. +15 −0 gson/src/test/java/com/gilecode/yagson/tests/checkers/EqualityChecker.java
  100. +15 −0 gson/src/test/java/com/gilecode/yagson/tests/checkers/EqualityCheckersFactory.java
  101. +15 −0 gson/src/test/java/com/gilecode/yagson/tests/checkers/NullChecker.java
  102. +15 −0 gson/src/test/java/com/gilecode/yagson/tests/checkers/SafeEqualsChecker.java
  103. +15 −0 gson/src/test/java/com/gilecode/yagson/tests/checkers/ToStringEqualityChecker.java
  104. +15 −0 gson/src/test/java/com/gilecode/yagson/tests/data/ClassWithObject.java
  105. +15 −0 gson/src/test/java/com/gilecode/yagson/tests/data/Person.java
  106. +15 −0 gson/src/test/java/com/gilecode/yagson/tests/data/PersonEx.java
  107. +15 −0 gson/src/test/java/com/gilecode/yagson/tests/util/BindingTestCase.java
  108. +15 −0 gson/src/test/java/com/gilecode/yagson/tests/util/EqualityCheckMode.java
  109. +15 −0 gson/src/test/java/com/gilecode/yagson/tests/util/Pair.java
  110. +15 −0 gson/src/test/java/com/gilecode/yagson/tests/util/TestUtils.java
  111. +15 −0 gson/src/test/java/com/gilecode/yagson/tests/util/Triple.java
  112. +2 −0 gson/src/test/java/com/google/gson/GsonBuilderTest.java
  113. +1 −0 gson/src/test/java/com/google/gson/JsonParserTest.java
  114. +1 −0 gson/src/test/java/com/google/gson/ObjectTypeAdapterTest.java
  115. +2 −0 gson/src/test/java/com/google/gson/OverrideCoreTypeAdaptersTest.java
  116. +1 −0 gson/src/test/java/com/google/gson/functional/CircularReferenceTest.java
  117. +1 −0 gson/src/test/java/com/google/gson/functional/CollectionTest.java
  118. +2 −1 gson/src/test/java/com/google/gson/functional/DefaultTypeAdaptersTest.java
  119. +1 −0 gson/src/test/java/com/google/gson/functional/DelegateTypeAdapterTest.java
  120. +1 −0 gson/src/test/java/com/google/gson/functional/FieldExclusionTest.java
  121. +2 −1 gson/src/test/java/com/google/gson/functional/JsonAdapterAnnotationOnClassesTest.java
  122. +2 −1 gson/src/test/java/com/google/gson/functional/JsonAdapterAnnotationOnFieldsTest.java
  123. +1 −0 gson/src/test/java/com/google/gson/functional/MoreSpecificTypeSerializationTest.java
  124. +1 −0 gson/src/test/java/com/google/gson/functional/ObjectTest.java
  125. +1 −0 gson/src/test/java/com/google/gson/functional/RuntimeTypeAdapterFactoryFunctionalTest.java
  126. +2 −1 gson/src/test/java/com/google/gson/functional/StreamingTypeAdaptersTest.java
  127. +2 −1 gson/src/test/java/com/google/gson/functional/TypeAdapterPrecedenceTest.java
View
@@ -1,4 +1,5 @@
Copyright 2008 Google Inc.
Original Gson: Copyright 2008 Google Inc.
YaGson and related modifications: Copyright 2016 Andrey Mogilev
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -1,12 +1,27 @@
/*
* Copyright (C) 2016 Andrey Mogilev
*
* 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.gilecode.yagson;
import com.gilecode.yagson.refs.References;
import com.gilecode.yagson.refs.ReferencesPolicy;
import com.gilecode.yagson.refs.ReferencesReadContext;
import com.google.gson.Gson;
import com.google.gson.TypeAdapter;
import com.google.gson.internal.bind.AdapterUtils;
import com.google.gson.internal.bind.TypeAdviceReadingSimpleAdapterWrapper;
import com.gilecode.yagson.adapters.AdapterUtils;
import com.gilecode.yagson.adapters.TypeAdviceReadingSimpleAdapterWrapper;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonToken;
@@ -1,3 +1,18 @@
/*
* Copyright (C) 2016 Andrey Mogilev
*
* 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.gilecode.yagson;
import com.gilecode.yagson.refs.References;
@@ -1,3 +1,18 @@
/*
* Copyright (C) 2016 Andrey Mogilev
*
* 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.gilecode.yagson;
import com.gilecode.yagson.refs.References;
@@ -1,3 +1,18 @@
/*
* Copyright (C) 2016 Andrey Mogilev
*
* 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.gilecode.yagson;
import com.gilecode.yagson.refs.References;
@@ -1,4 +1,19 @@
package com.google.gson.internal.bind;
/*
* Copyright (C) 2016 Andrey Mogilev
*
* 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.gilecode.yagson.adapters;
import com.gilecode.yagson.ReadContext;
import com.gilecode.yagson.WriteContext;
@@ -8,9 +23,10 @@
import com.gilecode.yagson.types.TypeUtils;
import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;
import com.google.gson.SimpleTypeAdapter;
import com.google.gson.TypeAdapter;
import com.google.gson.internal.Excluder;
import com.google.gson.internal.bind.ReflectiveTypeAdapterFactory;
import com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper;
import com.google.gson.reflect.TypeToken;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
@@ -0,0 +1,100 @@
/*
* Copyright (C) 2016 Andrey Mogilev
*
* 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.gilecode.yagson.adapters;
import com.gilecode.yagson.ReadContext;
import com.gilecode.yagson.WriteContext;
import com.gilecode.yagson.types.TypeUtils;
import com.google.gson.Gson;
import com.google.gson.TypeAdapter;
import com.google.gson.reflect.TypeToken;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonToken;
import com.google.gson.stream.JsonWriter;
import java.io.IOException;
import java.lang.reflect.Type;
/**
* Type adapter wrapper with the advanced support of the type advices and the default types. Emits/use type advices only
* when the runtime type differs from the default type.
* <p/>
* This wrapper may only be used when the type info is enabled.
*
* @author Andrey Mogilev
*/
public final class DefaultTypeAdapterRuntimeWrapper<T> extends TypeAdapter<T> {
private final Gson gson;
/**
* The formal (super)type, corresponds to T
*/
private final Type formalType;
/**
* The default class. Objects of this exact class are wriiten without type advices.
*/
private final Class<? extends T> defaultRawType;
/**
* The type adapter used for objects of the default type.
*/
private final TypeAdapter<T> defaultTypeAdapter;
public DefaultTypeAdapterRuntimeWrapper(Gson gson, Class<? extends T> defaultRawType, Type formalType) {
assert gson.getTypeInfoPolicy().isEnabled() : "Requires enabled type info";
this.gson = gson;
this.defaultRawType = defaultRawType;
this.formalType = formalType;
this.defaultTypeAdapter = getTypeAdapterFor(defaultRawType);
}
private TypeAdapter<T> getTypeAdapterFor(Class<? extends T> rawType) {
Type type = TypeUtils.mergeTypes(rawType, formalType);
return (TypeAdapter<T>) gson.getAdapter(TypeToken.get(type));
}
@Override
public T read(JsonReader in, ReadContext ctx) throws IOException {
// Although similar check exists in ReadContext.doRead(), we need to duplicate it here, as wrappers hide
// simple delegate adapters
if (in.peek() == JsonToken.BEGIN_OBJECT && AdapterUtils.isSimpleTypeAdapter(defaultTypeAdapter)) {
// if default adapter is simple and '{' is found, we expect and parse type advice here, and fail otherwise
return TypeUtils.readTypeAdvisedValue(gson, in, formalType, ctx);
} else {
// no type advice, or defaultTypeAdapter is able to process type advice itself, as it is non-Simple
return defaultTypeAdapter.read(in, ctx);
}
}
@SuppressWarnings({"rawtypes", "unchecked"})
@Override
public void write(JsonWriter out, T value, WriteContext ctx) throws IOException {
boolean useDefault = value == null || value.getClass() == defaultRawType;
TypeAdapter chosen = useDefault ? defaultTypeAdapter : getTypeAdapterFor((Class<? extends T>) value.getClass());
if (useDefault) {
chosen.write(out, value, ctx);
} else {
TypeUtils.writeTypeWrapperAndValue(out, value, chosen, ctx);
}
}
}
@@ -0,0 +1,31 @@
/*
* Copyright (C) 2016 Andrey Mogilev
*
* 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.gilecode.yagson.adapters;
import com.google.gson.TypeAdapter;
/**
* Abstract for type adapter wrappers with known delegates.
* Once initialized, returns the same delegate on each call to {@link #getDelegate()} }
*/
public abstract class DelegatingTypeAdapter<T> extends TypeAdapter<T> {
protected TypeAdapter<T> delegate;
public TypeAdapter<T> getDelegate() {
return delegate;
}
}
@@ -0,0 +1,22 @@
/*
* Copyright (C) 2016 Andrey Mogilev
*
* 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.gilecode.yagson.adapters;
import java.lang.reflect.Field;
public interface HasField {
Field getField();
}
@@ -0,0 +1,55 @@
/*
* Copyright (C) 2016 Andrey Mogilev
*
* 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.gilecode.yagson.adapters;
import java.io.IOException;
import com.gilecode.yagson.ReadContext;
import com.gilecode.yagson.WriteContext;
import com.google.gson.TypeAdapter;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
/**
* Type adapter for primitive or simple values, which are known to not contain any child objects inside, and
* the generated JSON representation does not contain JSON Objects or Arrays ('{...}' and '[...]'}.
* <p/>
* In particular, it means that the corresponding objects cannot contain circular dependencies.
* <p/>
* For convenience, in all current references policies, no references are created for such primitove objects.
* Otherwise, in references policies like 'all duplicates', we could have many annoying references for values like empty
* string, zero etc.
*
* @author Andrey Mogilev
*/
public abstract class SimpleTypeAdapter<T> extends TypeAdapter<T> {
abstract public void write(JsonWriter out, T value) throws IOException;
abstract public T read(JsonReader in) throws IOException;
@Override
public T read(JsonReader in, ReadContext ctx) throws IOException {
T value = read(in);
ctx.registerObject(value, true);
return value;
}
@Override
public void write(JsonWriter out, T value, WriteContext ctx) throws IOException {
write(out, value);
}
}
@@ -1,3 +1,18 @@
/*
* Copyright (C) 2016 Andrey Mogilev
*
* 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.gilecode.yagson.adapters;
import com.gilecode.yagson.WriteContext;
@@ -1,22 +1,23 @@
/*
* Copyright (C) 2011 Google Inc.
* Copyright (C) 2016 Andrey Mogilev
*
* 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
* 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.bind;
package com.gilecode.yagson.adapters;
import com.gilecode.yagson.ReadContext;
import com.gilecode.yagson.WriteContext;
import com.gilecode.yagson.adapters.AdapterUtils;
import com.gilecode.yagson.types.TypeUtils;
import com.google.gson.Gson;
import com.google.gson.TypeAdapter;
Oops, something went wrong.

0 comments on commit c7dbae8

Please sign in to comment.