47 |
48 |
49 |
50 |
--------------------------------------------------------------------------------
/gson/docs/javadocs/package-list:
--------------------------------------------------------------------------------
1 | com.google.gson
2 | com.google.gson.annotations
3 | com.google.gson.reflect
4 | com.google.gson.stream
5 |
--------------------------------------------------------------------------------
/gson/docs/javadocs/resources/inherit.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YangLang116/IKGson/5873a9632b7462000545afd766e0d1085850ae49/gson/docs/javadocs/resources/inherit.gif
--------------------------------------------------------------------------------
/gson/docs/javadocs/script.js:
--------------------------------------------------------------------------------
1 | function show(type)
2 | {
3 | count = 0;
4 | for (var key in methods) {
5 | var row = document.getElementById(key);
6 | if ((methods[key] & type) != 0) {
7 | row.style.display = '';
8 | row.className = (count++ % 2) ? rowColor : altColor;
9 | }
10 | else
11 | row.style.display = 'none';
12 | }
13 | updateTabs(type);
14 | }
15 |
16 | function updateTabs(type)
17 | {
18 | for (var value in tabs) {
19 | var sNode = document.getElementById(tabs[value][0]);
20 | var spanNode = sNode.firstChild;
21 | if (value == type) {
22 | sNode.className = activeTableTab;
23 | spanNode.innerHTML = tabs[value][1];
24 | }
25 | else {
26 | sNode.className = tableTab;
27 | spanNode.innerHTML = "" + tabs[value][1] + "";
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/gson/docs/javadocs/stylesheet.css:
--------------------------------------------------------------------------------
1 | /* Javadoc style sheet */
2 |
3 | /* Define colors, fonts and other style attributes here to override the defaults */
4 |
5 | /* Page background color */
6 | body { background-color: #FFFFFF; color:#000000 }
7 |
8 | /* Headings */
9 | h1 { font-size: 145% }
10 |
11 | /* Table colors */
12 | .TableHeadingColor { background: #CCCCFF; color:#000000 } /* Dark mauve */
13 | .TableSubHeadingColor { background: #EEEEFF; color:#000000 } /* Light mauve */
14 | .TableRowColor { background: #FFFFFF; color:#000000 } /* White */
15 |
16 | /* Font used in left-hand frame lists */
17 | .FrameTitleFont { font-size: 100%; font-family: Helvetica, Arial, sans-serif; color:#000000 }
18 | .FrameHeadingFont { font-size: 90%; font-family: Helvetica, Arial, sans-serif; color:#000000 }
19 | .FrameItemFont { font-size: 90%; font-family: Helvetica, Arial, sans-serif; color:#000000 }
20 |
21 | /* Navigation bar fonts and colors */
22 | .NavBarCell1 { background-color:#EEEEFF; color:#000000} /* Light mauve */
23 | .NavBarCell1Rev { background-color:#00008B; color:#FFFFFF} /* Dark Blue */
24 | .NavBarFont1 { font-family: Arial, Helvetica, sans-serif; color:#000000;color:#000000;}
25 | .NavBarFont1Rev { font-family: Arial, Helvetica, sans-serif; color:#FFFFFF;color:#FFFFFF;}
26 |
27 | .NavBarCell2 { font-family: Arial, Helvetica, sans-serif; background-color:#FFFFFF; color:#000000}
28 | .NavBarCell3 { font-family: Arial, Helvetica, sans-serif; background-color:#FFFFFF; color:#000000}
29 |
30 |
--------------------------------------------------------------------------------
/gson/pom.xml:
--------------------------------------------------------------------------------
1 |
2 | 4.0.0
3 |
4 |
5 | com.google.code.gson
6 | gson-parent
7 | 2.8.2-SNAPSHOT
8 |
9 |
10 | gson
11 | Gson
12 |
13 |
14 |
15 | junit
16 | junit
17 | test
18 |
19 |
20 |
21 |
22 |
23 |
24 | org.apache.maven.plugins
25 | maven-javadoc-plugin
26 |
27 | com.google.gson
28 | com.google.gson.internal:com.google.gson.internal.bind
29 |
30 | http://docs.oracle.com/javase/6/docs/api/
31 |
32 |
33 |
34 |
35 | biz.aQute.bnd
36 | bnd-maven-plugin
37 | 3.1.0
38 |
39 |
40 |
41 | bnd-process
42 |
43 |
44 |
45 |
46 |
47 | org.apache.maven.plugins
48 | maven-jar-plugin
49 |
50 |
51 | ${project.build.outputDirectory}/META-INF/MANIFEST.MF
52 |
53 |
54 |
55 |
56 | org.apache.felix
57 | maven-bundle-plugin
58 |
59 |
60 |
61 |
62 |
--------------------------------------------------------------------------------
/gson/src/main/java/com/google/gson/FieldNamingStrategy.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2008 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.gson;
18 |
19 | import java.lang.reflect.Field;
20 |
21 | /**
22 | * A mechanism for providing custom field naming in Gson. This allows the client code to translate
23 | * field names into a particular convention that is not supported as a normal Java field
24 | * declaration rules. For example, Java does not support "-" characters in a field name.
25 | *
26 | * @author Inderjeet Singh
27 | * @author Joel Leitch
28 | * @since 1.3
29 | */
30 | public interface FieldNamingStrategy {
31 |
32 | /**
33 | * Translates the field name into its JSON field name representation.
34 | *
35 | * @param f the field object that we are translating
36 | * @return the translated field name.
37 | * @since 1.3
38 | */
39 | public String translateName(Field f);
40 | }
41 |
--------------------------------------------------------------------------------
/gson/src/main/java/com/google/gson/JsonDeserializationContext.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2008 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.gson;
18 |
19 | import java.lang.reflect.Type;
20 |
21 | /**
22 | * Context for deserialization that is passed to a custom deserializer during invocation of its
23 | * {@link JsonDeserializer#deserialize(JsonElement, Type, JsonDeserializationContext)}
24 | * method.
25 | *
26 | * @author Inderjeet Singh
27 | * @author Joel Leitch
28 | */
29 | public interface JsonDeserializationContext {
30 |
31 | /**
32 | * Invokes default deserialization on the specified object. It should never be invoked on
33 | * the element received as a parameter of the
34 | * {@link JsonDeserializer#deserialize(JsonElement, Type, JsonDeserializationContext)} method. Doing
35 | * so will result in an infinite loop since Gson will in-turn call the custom deserializer again.
36 | *
37 | * @param json the parse tree.
38 | * @param typeOfT type of the expected return value.
39 | * @param The type of the deserialized object.
40 | * @return An object of type typeOfT.
41 | * @throws JsonParseException if the parse tree does not contain expected data.
42 | */
43 | public T deserialize(JsonElement json, Type typeOfT) throws JsonParseException;
44 | }
--------------------------------------------------------------------------------
/gson/src/main/java/com/google/gson/JsonIOException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2008 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.google.gson;
17 |
18 | /**
19 | * This exception is raised when Gson was unable to read an input stream
20 | * or write to one.
21 | *
22 | * @author Inderjeet Singh
23 | * @author Joel Leitch
24 | */
25 | public final class JsonIOException extends JsonParseException {
26 | private static final long serialVersionUID = 1L;
27 |
28 | public JsonIOException(String msg) {
29 | super(msg);
30 | }
31 |
32 | public JsonIOException(String msg, Throwable cause) {
33 | super(msg, cause);
34 | }
35 |
36 | /**
37 | * Creates exception with the specified cause. Consider using
38 | * {@link #JsonIOException(String, Throwable)} instead if you can describe what happened.
39 | *
40 | * @param cause root exception that caused this exception to be thrown.
41 | */
42 | public JsonIOException(Throwable cause) {
43 | super(cause);
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/gson/src/main/java/com/google/gson/JsonNull.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2008 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.gson;
18 |
19 | /**
20 | * A class representing a Json {@code null} value.
21 | *
22 | * @author Inderjeet Singh
23 | * @author Joel Leitch
24 | * @since 1.2
25 | */
26 | public final class JsonNull extends JsonElement {
27 | /**
28 | * singleton for JsonNull
29 | *
30 | * @since 1.8
31 | */
32 | public static final JsonNull INSTANCE = new JsonNull();
33 |
34 | /**
35 | * Creates a new JsonNull object.
36 | * Deprecated since Gson version 1.8. Use {@link #INSTANCE} instead
37 | */
38 | @Deprecated
39 | public JsonNull() {
40 | // Do nothing
41 | }
42 |
43 | /**
44 | * Returns the same instance since it is an immutable value
45 | * @since 2.8.2
46 | */
47 | @Override
48 | public JsonNull deepCopy() {
49 | return INSTANCE;
50 | }
51 |
52 | /**
53 | * All instances of JsonNull have the same hash code since they are indistinguishable
54 | */
55 | @Override
56 | public int hashCode() {
57 | return JsonNull.class.hashCode();
58 | }
59 |
60 | /**
61 | * All instances of JsonNull are the same
62 | */
63 | @Override
64 | public boolean equals(Object other) {
65 | return this == other || other instanceof JsonNull;
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/gson/src/main/java/com/google/gson/JsonParseException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2008 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.gson;
18 |
19 | /**
20 | * This exception is raised if there is a serious issue that occurs during parsing of a Json
21 | * string. One of the main usages for this class is for the Gson infrastructure. If the incoming
22 | * Json is bad/malicious, an instance of this exception is raised.
23 | *
24 | *
This exception is a {@link RuntimeException} because it is exposed to the client. Using a
25 | * {@link RuntimeException} avoids bad coding practices on the client side where they catch the
26 | * exception and do nothing. It is often the case that you want to blow up if there is a parsing
27 | * error (i.e. often clients do not know how to recover from a {@link JsonParseException}.
28 | *
29 | * @author Inderjeet Singh
30 | * @author Joel Leitch
31 | */
32 | public class JsonParseException extends RuntimeException {
33 | static final long serialVersionUID = -4086729973971783390L;
34 |
35 | /**
36 | * Creates exception with the specified message. If you are wrapping another exception, consider
37 | * using {@link #JsonParseException(String, Throwable)} instead.
38 | *
39 | * @param msg error message describing a possible cause of this exception.
40 | */
41 | public JsonParseException(String msg) {
42 | super(msg);
43 | }
44 |
45 | /**
46 | * Creates exception with the specified message and cause.
47 | *
48 | * @param msg error message describing what happened.
49 | * @param cause root exception that caused this exception to be thrown.
50 | */
51 | public JsonParseException(String msg, Throwable cause) {
52 | super(msg, cause);
53 | }
54 |
55 | /**
56 | * Creates exception with the specified cause. Consider using
57 | * {@link #JsonParseException(String, Throwable)} instead if you can describe what happened.
58 | *
59 | * @param cause root exception that caused this exception to be thrown.
60 | */
61 | public JsonParseException(Throwable cause) {
62 | super(cause);
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/gson/src/main/java/com/google/gson/JsonParser.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2009 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.google.gson;
17 |
18 | import java.io.IOException;
19 | import java.io.Reader;
20 | import java.io.StringReader;
21 |
22 | import com.google.gson.internal.Streams;
23 | import com.google.gson.stream.JsonReader;
24 | import com.google.gson.stream.JsonToken;
25 | import com.google.gson.stream.MalformedJsonException;
26 |
27 | /**
28 | * A parser to parse Json into a parse tree of {@link JsonElement}s
29 | *
30 | * @author Inderjeet Singh
31 | * @author Joel Leitch
32 | * @since 1.3
33 | */
34 | public final class JsonParser {
35 |
36 | /**
37 | * Parses the specified JSON string into a parse tree
38 | *
39 | * @param json JSON text
40 | * @return a parse tree of {@link JsonElement}s corresponding to the specified JSON
41 | * @throws JsonParseException if the specified text is not valid JSON
42 | * @since 1.3
43 | */
44 | public JsonElement parse(String json) throws JsonSyntaxException {
45 | return parse(new StringReader(json));
46 | }
47 |
48 | /**
49 | * Parses the specified JSON string into a parse tree
50 | *
51 | * @param json JSON text
52 | * @return a parse tree of {@link JsonElement}s corresponding to the specified JSON
53 | * @throws JsonParseException if the specified text is not valid JSON
54 | * @since 1.3
55 | */
56 | public JsonElement parse(Reader json) throws JsonIOException, JsonSyntaxException {
57 | try {
58 | JsonReader jsonReader = new JsonReader(json);
59 | JsonElement element = parse(jsonReader);
60 | if (!element.isJsonNull() && jsonReader.peek() != JsonToken.END_DOCUMENT) {
61 | throw new JsonSyntaxException("Did not consume the entire document.");
62 | }
63 | return element;
64 | } catch (MalformedJsonException e) {
65 | throw new JsonSyntaxException(e);
66 | } catch (IOException e) {
67 | throw new JsonIOException(e);
68 | } catch (NumberFormatException e) {
69 | throw new JsonSyntaxException(e);
70 | }
71 | }
72 |
73 | /**
74 | * Returns the next value from the JSON stream as a parse tree.
75 | *
76 | * @throws JsonParseException if there is an IOException or if the specified
77 | * text is not valid JSON
78 | * @since 1.6
79 | */
80 | public JsonElement parse(JsonReader json) throws JsonIOException, JsonSyntaxException {
81 | boolean lenient = json.isLenient();
82 | json.setLenient(true);
83 | try {
84 | return Streams.parse(json);
85 | } catch (StackOverflowError e) {
86 | throw new JsonParseException("Failed parsing JSON source: " + json + " to Json", e);
87 | } catch (OutOfMemoryError e) {
88 | throw new JsonParseException("Failed parsing JSON source: " + json + " to Json", e);
89 | } finally {
90 | json.setLenient(lenient);
91 | }
92 | }
93 | }
94 |
--------------------------------------------------------------------------------
/gson/src/main/java/com/google/gson/JsonSerializationContext.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2008 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.gson;
18 |
19 | import java.lang.reflect.Type;
20 |
21 | /**
22 | * Context for serialization that is passed to a custom serializer during invocation of its
23 | * {@link JsonSerializer#serialize(Object, Type, JsonSerializationContext)} method.
24 | *
25 | * @author Inderjeet Singh
26 | * @author Joel Leitch
27 | */
28 | public interface JsonSerializationContext {
29 |
30 | /**
31 | * Invokes default serialization on the specified object.
32 | *
33 | * @param src the object that needs to be serialized.
34 | * @return a tree of {@link JsonElement}s corresponding to the serialized form of {@code src}.
35 | */
36 | public JsonElement serialize(Object src);
37 |
38 | /**
39 | * Invokes default serialization on the specified object passing the specific type information.
40 | * It should never be invoked on the element received as a parameter of the
41 | * {@link JsonSerializer#serialize(Object, Type, JsonSerializationContext)} method. Doing
42 | * so will result in an infinite loop since Gson will in-turn call the custom serializer again.
43 | *
44 | * @param src the object that needs to be serialized.
45 | * @param typeOfSrc the actual genericized type of src object.
46 | * @return a tree of {@link JsonElement}s corresponding to the serialized form of {@code src}.
47 | */
48 | public JsonElement serialize(Object src, Type typeOfSrc);
49 | }
50 |
--------------------------------------------------------------------------------
/gson/src/main/java/com/google/gson/JsonSyntaxException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.google.gson;
17 |
18 | /**
19 | * This exception is raised when Gson attempts to read (or write) a malformed
20 | * JSON element.
21 | *
22 | * @author Inderjeet Singh
23 | * @author Joel Leitch
24 | */
25 | public final class JsonSyntaxException extends JsonParseException {
26 |
27 | private static final long serialVersionUID = 1L;
28 |
29 | public JsonSyntaxException(String msg) {
30 | super(msg);
31 | }
32 |
33 | public JsonSyntaxException(String msg, Throwable cause) {
34 | super(msg, cause);
35 | }
36 |
37 | /**
38 | * Creates exception with the specified cause. Consider using
39 | * {@link #JsonSyntaxException(String, Throwable)} instead if you can
40 | * describe what actually happened.
41 | *
42 | * @param cause root exception that caused this exception to be thrown.
43 | */
44 | public JsonSyntaxException(Throwable cause) {
45 | super(cause);
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/gson/src/main/java/com/google/gson/LongSerializationPolicy.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2009 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.gson;
18 |
19 | /**
20 | * Defines the expected format for a {@code long} or {@code Long} type when its serialized.
21 | *
22 | * @since 1.3
23 | *
24 | * @author Inderjeet Singh
25 | * @author Joel Leitch
26 | */
27 | public enum LongSerializationPolicy {
28 | /**
29 | * This is the "default" serialization policy that will output a {@code long} object as a JSON
30 | * number. For example, assume an object has a long field named "f" then the serialized output
31 | * would be:
32 | * {@code {"f":123}}.
33 | */
34 | DEFAULT() {
35 | @Override public JsonElement serialize(Long value) {
36 | return new JsonPrimitive(value);
37 | }
38 | },
39 |
40 | /**
41 | * Serializes a long value as a quoted string. For example, assume an object has a long field
42 | * named "f" then the serialized output would be:
43 | * {@code {"f":"123"}}.
44 | */
45 | STRING() {
46 | @Override public JsonElement serialize(Long value) {
47 | return new JsonPrimitive(String.valueOf(value));
48 | }
49 | };
50 |
51 | /**
52 | * Serialize this {@code value} using this serialization policy.
53 | *
54 | * @param value the long value to be serialized into a {@link JsonElement}
55 | * @return the serialized version of {@code value}
56 | */
57 | public abstract JsonElement serialize(Long value);
58 | }
59 |
--------------------------------------------------------------------------------
/gson/src/main/java/com/google/gson/annotations/SerializedName.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2008 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.gson.annotations;
18 |
19 | import java.lang.annotation.Documented;
20 | import java.lang.annotation.ElementType;
21 | import java.lang.annotation.Retention;
22 | import java.lang.annotation.RetentionPolicy;
23 | import java.lang.annotation.Target;
24 |
25 | /**
26 | * An annotation that indicates this member should be serialized to JSON with
27 | * the provided name value as its field name.
28 | *
29 | *
This annotation will override any {@link com.google.gson.FieldNamingPolicy}, including
30 | * the default field naming policy, that may have been set on the {@link com.google.gson.Gson}
31 | * instance. A different naming policy can set using the {@code GsonBuilder} class. See
32 | * {@link com.google.gson.GsonBuilder#setFieldNamingPolicy(com.google.gson.FieldNamingPolicy)}
33 | * for more information.
34 | *
35 | *
Here is an example of how this annotation is meant to be used:
73 | * Note that MyClass.b is now deserialized from either name1, name2 or name3.
74 | *
75 | * @see com.google.gson.FieldNamingPolicy
76 | *
77 | * @author Inderjeet Singh
78 | * @author Joel Leitch
79 | */
80 | @Documented
81 | @Retention(RetentionPolicy.RUNTIME)
82 | @Target({ElementType.FIELD, ElementType.METHOD})
83 | public @interface SerializedName {
84 |
85 | /**
86 | * @return the desired name of the field when it is serialized or deserialized
87 | */
88 | String value();
89 | /**
90 | * @return the alternative names of the field when it is deserialized
91 | */
92 | String[] alternate() default {};
93 | }
94 |
--------------------------------------------------------------------------------
/gson/src/main/java/com/google/gson/annotations/Since.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2008 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.gson.annotations;
18 |
19 | import java.lang.annotation.Documented;
20 | import java.lang.annotation.ElementType;
21 | import java.lang.annotation.Retention;
22 | import java.lang.annotation.RetentionPolicy;
23 | import java.lang.annotation.Target;
24 |
25 | /**
26 | * An annotation that indicates the version number since a member or a type has been present.
27 | * This annotation is useful to manage versioning of your Json classes for a web-service.
28 | *
29 | *
30 | * This annotation has no effect unless you build {@link com.google.gson.Gson} with a
31 | * {@link com.google.gson.GsonBuilder} and invoke
32 | * {@link com.google.gson.GsonBuilder#setVersion(double)} method.
33 | *
34 | *
Here is an example of how this annotation is meant to be used:
If you created Gson with {@code new Gson()}, the {@code toJson()} and {@code fromJson()}
46 | * methods will use all the fields for serialization and deserialization. However, if you created
47 | * Gson with {@code Gson gson = new GsonBuilder().setVersion(1.0).create()} then the
48 | * {@code toJson()} and {@code fromJson()} methods of Gson will exclude the {@code address} field
49 | * since it's version number is set to {@code 1.1}.
50 | *
51 | * @author Inderjeet Singh
52 | * @author Joel Leitch
53 | */
54 | @Documented
55 | @Retention(RetentionPolicy.RUNTIME)
56 | @Target({ElementType.FIELD, ElementType.TYPE})
57 | public @interface Since {
58 | /**
59 | * the value indicating a version number since this member
60 | * or type has been present.
61 | */
62 | double value();
63 | }
64 |
--------------------------------------------------------------------------------
/gson/src/main/java/com/google/gson/annotations/Until.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2008 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.gson.annotations;
18 |
19 | import java.lang.annotation.Documented;
20 | import java.lang.annotation.ElementType;
21 | import java.lang.annotation.Retention;
22 | import java.lang.annotation.RetentionPolicy;
23 | import java.lang.annotation.Target;
24 |
25 | /**
26 | * An annotation that indicates the version number until a member or a type should be present.
27 | * Basically, if Gson is created with a version number that exceeds the value stored in the
28 | * {@code Until} annotation then the field will be ignored from the JSON output. This annotation
29 | * is useful to manage versioning of your JSON classes for a web-service.
30 | *
31 | *
32 | * This annotation has no effect unless you build {@link com.google.gson.Gson} with a
33 | * {@link com.google.gson.GsonBuilder} and invoke
34 | * {@link com.google.gson.GsonBuilder#setVersion(double)} method.
35 | *
36 | *
Here is an example of how this annotation is meant to be used:
If you created Gson with {@code new Gson()}, the {@code toJson()} and {@code fromJson()}
47 | * methods will use all the fields for serialization and deserialization. However, if you created
48 | * Gson with {@code Gson gson = new GsonBuilder().setVersion(1.2).create()} then the
49 | * {@code toJson()} and {@code fromJson()} methods of Gson will exclude the {@code emailAddress}
50 | * and {@code password} fields from the example above, because the version number passed to the
51 | * GsonBuilder, {@code 1.2}, exceeds the version number set on the {@code Until} annotation,
52 | * {@code 1.1}, for those fields.
53 | *
54 | * @author Inderjeet Singh
55 | * @author Joel Leitch
56 | * @since 1.3
57 | */
58 | @Documented
59 | @Retention(RetentionPolicy.RUNTIME)
60 | @Target({ElementType.FIELD, ElementType.TYPE})
61 | public @interface Until {
62 |
63 | /**
64 | * the value indicating a version number until this member
65 | * or type should be ignored.
66 | */
67 | double value();
68 | }
69 |
--------------------------------------------------------------------------------
/gson/src/main/java/com/google/gson/annotations/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This package provides annotations that can be used with {@link com.google.gson.Gson}.
3 | *
4 | * @author Inderjeet Singh, Joel Leitch
5 | */
6 | package com.google.gson.annotations;
--------------------------------------------------------------------------------
/gson/src/main/java/com/google/gson/internal/$Gson$Preconditions.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2008 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.gson.internal;
18 |
19 | /**
20 | * A simple utility class used to check method Preconditions.
21 | *
22 | *
28 | *
29 | * @author Inderjeet Singh
30 | * @author Joel Leitch
31 | */
32 | public final class $Gson$Preconditions {
33 | private $Gson$Preconditions() {
34 | throw new UnsupportedOperationException();
35 | }
36 |
37 | public static T checkNotNull(T obj) {
38 | if (obj == null) {
39 | throw new NullPointerException();
40 | }
41 | return obj;
42 | }
43 |
44 | public static void checkArgument(boolean condition) {
45 | if (!condition) {
46 | throw new IllegalArgumentException();
47 | }
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/gson/src/main/java/com/google/gson/internal/JsonReaderInternalAccess.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.gson.internal;
18 |
19 | import com.google.gson.stream.JsonReader;
20 | import java.io.IOException;
21 |
22 | /**
23 | * Internal-only APIs of JsonReader available only to other classes in Gson.
24 | */
25 | public abstract class JsonReaderInternalAccess {
26 | public static JsonReaderInternalAccess INSTANCE;
27 |
28 | /**
29 | * Changes the type of the current property name token to a string value.
30 | */
31 | public abstract void promoteNameToValue(JsonReader reader) throws IOException;
32 | }
33 |
--------------------------------------------------------------------------------
/gson/src/main/java/com/google/gson/internal/LazilyParsedNumber.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.google.gson.internal;
17 |
18 | import java.io.ObjectStreamException;
19 | import java.math.BigDecimal;
20 |
21 | /**
22 | * This class holds a number value that is lazily converted to a specific number type
23 | *
24 | * @author Inderjeet Singh
25 | */
26 | public final class LazilyParsedNumber extends Number {
27 | private final String value;
28 |
29 | /** @param value must not be null */
30 | public LazilyParsedNumber(String value) {
31 | this.value = value;
32 | }
33 |
34 | @Override
35 | public int intValue() {
36 | try {
37 | return Integer.parseInt(value);
38 | } catch (NumberFormatException e) {
39 | try {
40 | return (int) Long.parseLong(value);
41 | } catch (NumberFormatException nfe) {
42 | return new BigDecimal(value).intValue();
43 | }
44 | }
45 | }
46 |
47 | @Override
48 | public long longValue() {
49 | try {
50 | return Long.parseLong(value);
51 | } catch (NumberFormatException e) {
52 | return new BigDecimal(value).longValue();
53 | }
54 | }
55 |
56 | @Override
57 | public float floatValue() {
58 | return Float.parseFloat(value);
59 | }
60 |
61 | @Override
62 | public double doubleValue() {
63 | return Double.parseDouble(value);
64 | }
65 |
66 | @Override
67 | public String toString() {
68 | return value;
69 | }
70 |
71 | /**
72 | * If somebody is unlucky enough to have to serialize one of these, serialize
73 | * it as a BigDecimal so that they won't need Gson on the other side to
74 | * deserialize it.
75 | */
76 | private Object writeReplace() throws ObjectStreamException {
77 | return new BigDecimal(value);
78 | }
79 |
80 | @Override
81 | public int hashCode() {
82 | return value.hashCode();
83 | }
84 |
85 | @Override
86 | public boolean equals(Object obj) {
87 | if (this == obj) {
88 | return true;
89 | }
90 | if (obj instanceof LazilyParsedNumber) {
91 | LazilyParsedNumber other = (LazilyParsedNumber) obj;
92 | return value == other.value || value.equals(other.value);
93 | }
94 | return false;
95 | }
96 | }
97 |
--------------------------------------------------------------------------------
/gson/src/main/java/com/google/gson/internal/ObjectConstructor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2008 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.gson.internal;
18 |
19 | /**
20 | * Defines a generic object construction factory. The purpose of this class
21 | * is to construct a default instance of a class that can be used for object
22 | * navigation while deserialization from its JSON representation.
23 | *
24 | * @author Inderjeet Singh
25 | * @author Joel Leitch
26 | */
27 | public interface ObjectConstructor {
28 |
29 | /**
30 | * Returns a new instance.
31 | */
32 | public T construct();
33 | }
--------------------------------------------------------------------------------
/gson/src/main/java/com/google/gson/internal/bind/DateTypeAdapter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.gson.internal.bind;
18 |
19 | import com.google.gson.Gson;
20 | import com.google.gson.JsonSyntaxException;
21 | import com.google.gson.TypeAdapter;
22 | import com.google.gson.TypeAdapterFactory;
23 | import com.google.gson.internal.bind.util.ISO8601Utils;
24 | import com.google.gson.reflect.TypeToken;
25 | import com.google.gson.stream.JsonReader;
26 | import com.google.gson.stream.JsonToken;
27 | import com.google.gson.stream.JsonWriter;
28 | import java.io.IOException;
29 | import java.text.DateFormat;
30 | import java.text.ParseException;
31 | import java.text.ParsePosition;
32 | import java.util.Date;
33 | import java.util.Locale;
34 |
35 | /**
36 | * Adapter for Date. Although this class appears stateless, it is not.
37 | * DateFormat captures its time zone and locale when it is created, which gives
38 | * this class state. DateFormat isn't thread safe either, so this class has
39 | * to synchronize its read and write methods.
40 | */
41 | public final class DateTypeAdapter extends TypeAdapter {
42 | public static final TypeAdapterFactory FACTORY = new TypeAdapterFactory() {
43 | @SuppressWarnings("unchecked") // we use a runtime check to make sure the 'T's equal
44 | @Override public TypeAdapter create(Gson gson, TypeToken typeToken) {
45 | return typeToken.getRawType() == Date.class ? (TypeAdapter) new DateTypeAdapter() : null;
46 | }
47 | };
48 |
49 | private final DateFormat enUsFormat
50 | = DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.DEFAULT, Locale.US);
51 | private final DateFormat localFormat
52 | = DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.DEFAULT);
53 |
54 | @Override public Date read(JsonReader in) throws IOException {
55 | if (in.peek() == JsonToken.NULL) {
56 | in.nextNull();
57 | return null;
58 | }
59 | return deserializeToDate(in.nextString());
60 | }
61 |
62 | private synchronized Date deserializeToDate(String json) {
63 | try {
64 | return localFormat.parse(json);
65 | } catch (ParseException ignored) {
66 | }
67 | try {
68 | return enUsFormat.parse(json);
69 | } catch (ParseException ignored) {
70 | }
71 | try {
72 | return ISO8601Utils.parse(json, new ParsePosition(0));
73 | } catch (ParseException e) {
74 | throw new JsonSyntaxException(json, e);
75 | }
76 | }
77 |
78 | @Override public synchronized void write(JsonWriter out, Date value) throws IOException {
79 | if (value == null) {
80 | out.nullValue();
81 | return;
82 | }
83 | String dateFormatAsString = enUsFormat.format(value);
84 | out.value(dateFormatAsString);
85 | }
86 |
87 |
88 | }
89 |
--------------------------------------------------------------------------------
/gson/src/main/java/com/google/gson/internal/bind/ObjectTypeAdapter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.gson.internal.bind;
18 |
19 | import com.google.gson.Gson;
20 | import com.google.gson.TypeAdapter;
21 | import com.google.gson.TypeAdapterFactory;
22 | import com.google.gson.internal.LinkedTreeMap;
23 | import com.google.gson.reflect.TypeToken;
24 | import com.google.gson.stream.JsonReader;
25 | import com.google.gson.stream.JsonToken;
26 | import com.google.gson.stream.JsonWriter;
27 |
28 | import java.io.IOException;
29 | import java.util.ArrayList;
30 | import java.util.List;
31 | import java.util.Map;
32 |
33 | /**
34 | * Adapts types whose static type is only 'Object'. Uses getClass() on
35 | * serialization and a primitive/Map/List on deserialization.
36 | */
37 | public final class ObjectTypeAdapter extends TypeAdapter