) typeConverterFactories.get(i).create(type, annotations);
124 | if (result != null) {
125 | return result;
126 | }
127 | }
128 | return null;
129 | }
130 |
131 | /**
132 | * Sometimes a type adapter factory depends on its own product; either directly or indirectly.
133 | * To make this work, we offer this type adapter stub while the final adapter is being computed.
134 | * When it is ready, we wire this to delegate to that finished adapter.
135 | *
136 | * Typically this is necessary in self-referential object models, such as an {@code Employee}
137 | * class that has a {@code List} field for an organization's management hierarchy.
138 | */
139 | private static class DeferredAdapter extends XmlAdapter {
140 | private Object cacheKey;
141 | private XmlAdapter delegate;
142 |
143 | public DeferredAdapter(Object cacheKey) {
144 | this.cacheKey = cacheKey;
145 | }
146 |
147 | public void ready(XmlAdapter delegate) {
148 | this.delegate = delegate;
149 | this.cacheKey = null;
150 | }
151 |
152 | @Override
153 | public T fromXml(XmlPullParser parser, TagInfo tagInfo) throws IOException, XmlPullParserException {
154 | if (delegate == null) throw new IllegalStateException("Type adapter isn't ready");
155 | return delegate.fromXml(parser, tagInfo);
156 | }
157 |
158 | @Override
159 | public void toXml(XmlSerializer serializer, TagInfo tagInfo, T value) throws IOException {
160 | if (delegate == null) throw new IllegalStateException("Type adapter isn't ready");
161 | delegate.toXml(serializer, tagInfo, value);
162 | }
163 | }
164 | }
165 |
--------------------------------------------------------------------------------
/parsnip/src/main/java/me/tatarka/parsnip/XmlDataException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Evan Tatarka.
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 me.tatarka.parsnip;
18 |
19 | /**
20 | * Created by evan on 6/15/15.
21 | */
22 | public class XmlDataException extends RuntimeException {
23 | public XmlDataException() {
24 | super();
25 | }
26 |
27 | public XmlDataException(String message) {
28 | super(message);
29 | }
30 |
31 | public XmlDataException(Throwable cause) {
32 | super(cause);
33 | }
34 |
35 | public XmlDataException(String message, Throwable cause) {
36 | super(message, cause);
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/parsnip/src/main/java/me/tatarka/parsnip/annotations/FromXml.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Evan Tatarka.
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 me.tatarka.parsnip.annotations;
17 |
18 | import java.lang.annotation.ElementType;
19 | import java.lang.annotation.Retention;
20 | import java.lang.annotation.RetentionPolicy;
21 | import java.lang.annotation.Target;
22 |
23 | @Retention(RetentionPolicy.RUNTIME)
24 | @Target(ElementType.METHOD)
25 | public @interface FromXml {
26 | }
27 |
--------------------------------------------------------------------------------
/parsnip/src/main/java/me/tatarka/parsnip/annotations/Namespace.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Evan Tatarka.
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 me.tatarka.parsnip.annotations;
18 |
19 | import java.lang.annotation.ElementType;
20 | import java.lang.annotation.Retention;
21 | import java.lang.annotation.RetentionPolicy;
22 | import java.lang.annotation.Target;
23 |
24 | /**
25 | * Created by evan on 7/3/15.
26 | */
27 | @Retention(RetentionPolicy.RUNTIME)
28 | @Target(ElementType.FIELD)
29 | public @interface Namespace {
30 |
31 | String alias() default "";
32 | String value();
33 | }
34 |
--------------------------------------------------------------------------------
/parsnip/src/main/java/me/tatarka/parsnip/annotations/SerializedName.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Evan Tatarka.
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 me.tatarka.parsnip.annotations;
18 |
19 | import java.lang.annotation.ElementType;
20 | import java.lang.annotation.Retention;
21 | import java.lang.annotation.RetentionPolicy;
22 | import java.lang.annotation.Target;
23 |
24 | @Retention(RetentionPolicy.RUNTIME)
25 | @Target({ElementType.FIELD, ElementType.TYPE})
26 | public @interface SerializedName {
27 | String value();
28 | }
29 |
--------------------------------------------------------------------------------
/parsnip/src/main/java/me/tatarka/parsnip/annotations/Tag.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Evan Tatarka.
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 me.tatarka.parsnip.annotations;
18 |
19 | import java.lang.annotation.ElementType;
20 | import java.lang.annotation.Retention;
21 | import java.lang.annotation.RetentionPolicy;
22 | import java.lang.annotation.Target;
23 |
24 | @Retention(RetentionPolicy.RUNTIME)
25 | @Target(ElementType.FIELD)
26 | @XmlQualifier
27 | public @interface Tag {
28 | }
29 |
--------------------------------------------------------------------------------
/parsnip/src/main/java/me/tatarka/parsnip/annotations/Text.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Evan Tatarka.
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 me.tatarka.parsnip.annotations;
18 |
19 | import java.lang.annotation.ElementType;
20 | import java.lang.annotation.Retention;
21 | import java.lang.annotation.RetentionPolicy;
22 | import java.lang.annotation.Target;
23 |
24 | @Retention(RetentionPolicy.RUNTIME)
25 | @Target(ElementType.FIELD)
26 | public @interface Text {
27 | }
28 |
--------------------------------------------------------------------------------
/parsnip/src/main/java/me/tatarka/parsnip/annotations/ToXml.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Evan Tatarka.
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 me.tatarka.parsnip.annotations;
17 |
18 | import java.lang.annotation.ElementType;
19 | import java.lang.annotation.Retention;
20 | import java.lang.annotation.RetentionPolicy;
21 | import java.lang.annotation.Target;
22 |
23 | @Retention(RetentionPolicy.RUNTIME)
24 | @Target(ElementType.METHOD)
25 | public @interface ToXml {
26 | }
27 |
--------------------------------------------------------------------------------
/parsnip/src/main/java/me/tatarka/parsnip/annotations/XmlQualifier.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Evan Tatarka.
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 me.tatarka.parsnip.annotations;
17 |
18 | import java.lang.annotation.Documented;
19 | import java.lang.annotation.Retention;
20 | import java.lang.annotation.Target;
21 |
22 | import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
23 | import static java.lang.annotation.RetentionPolicy.RUNTIME;
24 |
25 | /** Annotates another annotation, causing it to specialize how values are encoded and decoded. */
26 | @Target(ANNOTATION_TYPE)
27 | @Retention(RUNTIME)
28 | @Documented
29 | public @interface XmlQualifier {
30 | }
31 |
--------------------------------------------------------------------------------
/parsnip/src/test/kotlin/me/tatarka/parsnip/ObjectDeserializerSpecs.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Evan Tatarka.
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 me.tatarka.parsnip
18 |
19 | import me.tatarka.parsnip.classes.*
20 | import org.jetbrains.spek.api.Spek
21 | import org.jetbrains.spek.api.dsl.*
22 | import org.junit.platform.runner.JUnitPlatform
23 | import org.junit.runner.RunWith
24 | import kotlin.test.assertEquals
25 | import kotlin.test.assertNotNull
26 | import kotlin.test.assertNull
27 |
28 | @RunWith(JUnitPlatform::class)
29 | class ObjectDeserializerSpecs : Spek({
30 | describe("an Xml") {
31 | val xml by memoized { Xml.Builder().build() }
32 |
33 | context("an empty object") {
34 | val adapter = xml.adapter(EmptyObject::class.java)
35 | val emptyObject = adapter.fromXml("")
36 |
37 | it("should create the object") {
38 | assertNotNull(emptyObject)
39 | }
40 | }
41 |
42 | context("an object with a primitive attribute fields") {
43 | val adapter = xml.adapter(PrimitiveObject::class.java)
44 | val primitiveObject = adapter.fromXml("")
45 |
46 | it("should create the object") {
47 | assertNotNull(primitiveObject)
48 | }
49 |
50 | it("should set the boolean field") {
51 | assertEquals(true, primitiveObject.boolean)
52 | }
53 |
54 | it("should set the byte field") {
55 | assertEquals(1.toByte(), primitiveObject.byte)
56 | }
57 |
58 | it("should set the char field") {
59 | assertEquals('a', primitiveObject.char)
60 | }
61 |
62 | it("should set the double field") {
63 | assertEquals(1.0, primitiveObject.double)
64 | }
65 |
66 | it("should set the float field") {
67 | assertEquals(1.0F, primitiveObject.float)
68 | }
69 |
70 | it("should set the int field") {
71 | assertEquals(1, primitiveObject.int)
72 | }
73 |
74 | it("should set the long field") {
75 | assertEquals(1L, primitiveObject.long)
76 | }
77 |
78 | it("should set the short field") {
79 | assertEquals(1.toShort(), primitiveObject.short)
80 | }
81 | }
82 |
83 | context("an object with a string attribute field") {
84 | val adapter = xml.adapter(StringObject::class.java)
85 | val stringObject = adapter.fromXml("")
86 |
87 | it("should set the string1 field") {
88 | assertEquals("test", stringObject.string1)
89 | }
90 |
91 | it("should not set the string2 field") {
92 | assertNull(stringObject.string2)
93 | }
94 | }
95 |
96 | context("an object with an enum attribute field") {
97 | val adapter = xml.adapter(EnumObject::class.java)
98 | val enumObject = adapter.fromXml("")
99 |
100 | it("should set the enum1 field") {
101 | assertEquals(TestEnum.One, enumObject.enum1)
102 | }
103 |
104 | it("should set the enum2 field") {
105 | assertEquals(TestEnum.Two, enumObject.enum2)
106 | }
107 | }
108 |
109 | context("an object with a named enum attribute field") {
110 | val adapter = xml.adapter(NamedEnumObject::class.java)
111 | val enumObject = adapter.fromXml("")
112 |
113 | it("should set the enum1 field") {
114 | assertEquals(NamedTestEnum.One, enumObject.enum1)
115 | }
116 |
117 | it("should set the enum2 field") {
118 | assertEquals(NamedTestEnum.Two, enumObject.enum2)
119 | }
120 | }
121 |
122 | context("an object with a text field") {
123 | val adapter = xml.adapter(TextObject::class.java)
124 | val textObject = adapter.fromXml("test")
125 |
126 | it("should set the text field") {
127 | assertEquals("test", textObject.text)
128 | }
129 | }
130 |
131 | context("an object with a tag field") {
132 | val adapter = xml.adapter(TagObject::class.java)
133 | val tagObject = adapter.fromXml("test- test1
- test2
")
134 |
135 | it("should set the text field") {
136 | assertEquals("test", tagObject.text)
137 | }
138 |
139 | it("should set the items field") {
140 | assertEquals(listOf("test1", "test2"), tagObject.items)
141 | }
142 | }
143 |
144 | context("an object with a nested one") {
145 | val adapter = xml.adapter(NestedObject::class.java)
146 | val nestedObject = adapter.fromXml("")
147 |
148 | it("should set nested field") {
149 | assertNotNull(nestedObject.nested)
150 | }
151 |
152 | it("should set the nested object string1 field") {
153 | assertEquals("test", nestedObject.nested.string1)
154 | }
155 | }
156 |
157 | context("an object with a collection of tags") {
158 | val adapter = xml.adapter(CollectionObject::class.java)
159 | val collectionObject = adapter.fromXml(" ")
160 |
161 | it("should read the items into a collection") {
162 | assertEquals(listOf(StringObject("test1", null), StringObject("test2", null)), collectionObject.item)
163 | }
164 | }
165 |
166 | context("an object with namespaces") {
167 | val adapter = xml.adapter(NamespaceObject::class.java)
168 | val namespaceObject = adapter.fromXml("")
169 |
170 | it("should read the namespaced attribute, not the other one") {
171 | assertEquals("value", namespaceObject.attribute)
172 | }
173 |
174 | it("should read the namespaced tag") {
175 | assertEquals(StringObject("test", null), namespaceObject.tag)
176 | }
177 |
178 | it("should read the namespaced list") {
179 | assertEquals(listOf(StringObject("test1", null), StringObject("test2", null)), namespaceObject.item)
180 | }
181 | }
182 |
183 | context("an attribute and tag of the same name") {
184 | val adapter = xml.adapter(SameNameObject::class.java)
185 | val sameNameObject = adapter.fromXml("")
186 |
187 | it("should read the attribute") {
188 | assertEquals("value", sameNameObject.attribute)
189 | }
190 |
191 | it("should read the tag") {
192 | assertEquals(StringObject("value", null), sameNameObject.tag)
193 | }
194 | }
195 |
196 | context("an object without a namespace but xml with it") {
197 | val adapter = xml.adapter(StringObject::class.java)
198 | val stringObject = adapter.fromXml("")
199 |
200 | it("should read the attribute ignoring the namespace") {
201 | assertEquals("value", stringObject.string1)
202 | }
203 | }
204 | }
205 | })
--------------------------------------------------------------------------------
/parsnip/src/test/kotlin/me/tatarka/parsnip/ObjectSerializerSpecs.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Evan Tatarka.
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 me.tatarka.parsnip
18 |
19 | import me.tatarka.parsnip.classes.*
20 | import org.assertj.core.api.Assertions.assertThat
21 | import org.jetbrains.spek.api.Spek
22 | import org.jetbrains.spek.api.dsl.*
23 | import org.junit.platform.runner.JUnitPlatform
24 | import org.junit.runner.RunWith
25 | import kotlin.test.assertEquals
26 |
27 | @RunWith(JUnitPlatform::class)
28 | class ObjectSerializerSpecs : Spek({
29 | describe("an Xml") {
30 | val xml by memoized { Xml.Builder().build() }
31 |
32 | context("an empty object") {
33 | val adapter = xml.adapter(EmptyObject::class.java)
34 | val emptyObject = EmptyObject()
35 | val result = adapter.toXml(emptyObject)
36 |
37 | it("should write the object as a root tag") {
38 | assertEquals("", result)
39 | }
40 | }
41 |
42 | context("an object with primitive attribute fields") {
43 | val adapter = xml.adapter(PrimitiveObject::class.java)
44 | val primitiveObject = PrimitiveObject(
45 | boolean = true,
46 | byte = 1,
47 | char = 'a',
48 | double = 1.0,
49 | float = 1.0f,
50 | int = 1,
51 | long = 1L,
52 | short = 1
53 | )
54 | val result = adapter.toXml(primitiveObject)
55 |
56 | it("should write the object with the fields as attributes") {
57 | assertEquals("", result)
58 | }
59 | }
60 |
61 | context("an object with a string attribute field") {
62 | val adapter = xml.adapter(StringObject::class.java)
63 | val stringObject = StringObject(string1 = "test")
64 | val result = adapter.toXml(stringObject)
65 |
66 | it("should write the object with a string field attribute") {
67 | assertEquals("", result)
68 | }
69 | }
70 |
71 | context("an object with an enum attribute field") {
72 | val adapter = xml.adapter(EnumObject::class.java)
73 | val enumObject = EnumObject(enum1 = TestEnum.One, enum2 = TestEnum.Two)
74 | val result = adapter.toXml(enumObject)
75 |
76 | it("should write the enum attributes") {
77 | assertEquals("", result)
78 | }
79 | }
80 |
81 | context("an object with a named enum attribute field") {
82 | val adapter = xml.adapter(NamedEnumObject::class.java)
83 | val enumObject = NamedEnumObject(enum1 = NamedTestEnum.One, enum2 = NamedTestEnum.Two)
84 | val result = adapter.toXml(enumObject)
85 |
86 | it("should write the enum attributes") {
87 | assertEquals("", result)
88 | }
89 | }
90 |
91 | context("an object with a text field") {
92 | val adapter = xml.adapter(TextObject::class.java)
93 | val textObject = TextObject(text = "test")
94 | val result = adapter.toXml(textObject)
95 |
96 | it("should write the tag with text") {
97 | assertEquals("test", result)
98 | }
99 | }
100 |
101 | context("an object with a tag field") {
102 | val adapter = xml.adapter(TagObject::class.java)
103 | val tagObject = TagObject(text = "test", items = listOf("test1", "test2"))
104 | val result = adapter.toXml(tagObject)
105 |
106 | it("should write the text as a tag") {
107 | assertEquals("test- test1
- test2
", result)
108 | }
109 | }
110 |
111 | context("an object with a nested one") {
112 | val adapter = xml.adapter(NestedObject::class.java)
113 | val nestedObject = NestedObject(StringObject(string1 = "test"))
114 | val result = adapter.toXml(nestedObject)
115 |
116 | it("should write nested tags") {
117 | assertEquals("", result)
118 | }
119 | }
120 |
121 | context("an object with a namespace attribute") {
122 | val adapter = xml.adapter(NamespaceObject::class.java)
123 | val namespaceObject = NamespaceObject("value", StringObject(string1 = "value"), listOf(StringObject(string1 = "test1"), StringObject(string1 = "test2")))
124 | val result = adapter.toXml(namespaceObject)
125 |
126 | it("should write a namespaced attribute") {
127 | assertThat(result).isXmlEqualTo("")
128 | }
129 | }
130 |
131 | context("an object with an attribute and tag of the same name") {
132 | val adapter = xml.adapter(SameNameObject::class.java)
133 | val sameNameObject = SameNameObject("value", StringObject(string1 = "value"))
134 | val result = adapter.toXml(sameNameObject)
135 |
136 | it("should write the attribute and tag of the same name") {
137 | assertEquals("", result)
138 | }
139 | }
140 |
141 | context("an object with a collection of tags") {
142 | val adapter = xml.adapter(CollectionObject::class.java)
143 | val collectionObject = CollectionObject(listOf(StringObject(string1 = "test1"), StringObject(string1 = "test2")))
144 | val result = adapter.toXml(collectionObject)
145 |
146 | it("should write the items into a collection of tags") {
147 | assertEquals(" ", result)
148 | }
149 | }
150 | }
151 | });
152 |
--------------------------------------------------------------------------------
/parsnip/src/test/kotlin/me/tatarka/parsnip/classes/CollectionObject.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Evan Tatarka.
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 me.tatarka.parsnip.classes
18 |
19 | data
20 | public class CollectionObject(val item: List)
--------------------------------------------------------------------------------
/parsnip/src/test/kotlin/me/tatarka/parsnip/classes/EmptyObject.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Evan Tatarka.
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 me.tatarka.parsnip.classes
18 |
19 | public class EmptyObject
--------------------------------------------------------------------------------
/parsnip/src/test/kotlin/me/tatarka/parsnip/classes/EnumObject.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Evan Tatarka.
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 me.tatarka.parsnip.classes
18 |
19 | data
20 | class EnumObject(val enum1: TestEnum, val enum2: TestEnum)
21 |
22 | enum class TestEnum {
23 | One, Two
24 | }
25 |
26 |
--------------------------------------------------------------------------------
/parsnip/src/test/kotlin/me/tatarka/parsnip/classes/NamedEnumObject.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Evan Tatarka.
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 me.tatarka.parsnip.classes
18 |
19 | import me.tatarka.parsnip.annotations.SerializedName
20 |
21 | data
22 | class NamedEnumObject(val enum1: NamedTestEnum, val enum2: NamedTestEnum)
23 |
24 | enum class NamedTestEnum {
25 | @SerializedName("ONE")
26 | One,
27 | @SerializedName("TWO")
28 | Two
29 | }
30 |
31 |
--------------------------------------------------------------------------------
/parsnip/src/test/kotlin/me/tatarka/parsnip/classes/NamespaceObject.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Evan Tatarka.
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 me.tatarka.parsnip.classes
18 |
19 | import me.tatarka.parsnip.annotations.Namespace
20 |
21 | data
22 | class NamespaceObject(
23 | @Namespace("foo", alias = "ns") val attribute: String,
24 | @Namespace("foo", alias = "ns") val tag: StringObject,
25 | @Namespace("foo", alias = "ns") val item: List
26 | )
27 |
--------------------------------------------------------------------------------
/parsnip/src/test/kotlin/me/tatarka/parsnip/classes/NestedObject.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Evan Tatarka.
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 me.tatarka.parsnip.classes
18 |
19 | data
20 | public class NestedObject(val nested: StringObject)
21 |
--------------------------------------------------------------------------------
/parsnip/src/test/kotlin/me/tatarka/parsnip/classes/PrimitiveObject.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Evan Tatarka.
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 me.tatarka.parsnip.classes
18 |
19 | data
20 | public class PrimitiveObject(
21 | val boolean: Boolean,
22 | val byte: Byte,
23 | val char: Char,
24 | val double: Double,
25 | val float: Float,
26 | val int: Int,
27 | val long: Long,
28 | val short: Short
29 | )
--------------------------------------------------------------------------------
/parsnip/src/test/kotlin/me/tatarka/parsnip/classes/SameNameObject.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Evan Tatarka.
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 me.tatarka.parsnip.classes
18 |
19 | import me.tatarka.parsnip.annotations.SerializedName
20 |
21 | data
22 | class SameNameObject(@SerializedName("name") val attribute: String, @SerializedName("name") val tag: StringObject)
23 |
--------------------------------------------------------------------------------
/parsnip/src/test/kotlin/me/tatarka/parsnip/classes/StringObject.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Evan Tatarka.
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 me.tatarka.parsnip.classes
18 |
19 | data class StringObject(val string1: String? = null, val string2: String? = null)
20 |
--------------------------------------------------------------------------------
/parsnip/src/test/kotlin/me/tatarka/parsnip/classes/TagObject.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Evan Tatarka.
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 me.tatarka.parsnip.classes
18 |
19 | import me.tatarka.parsnip.annotations.SerializedName
20 | import me.tatarka.parsnip.annotations.Tag
21 |
22 | data
23 | public class TagObject(@Tag val text: String, @SerializedName("item") @Tag val items: List)
24 |
--------------------------------------------------------------------------------
/parsnip/src/test/kotlin/me/tatarka/parsnip/classes/TextObject.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Evan Tatarka.
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 me.tatarka.parsnip.classes
18 |
19 | import me.tatarka.parsnip.annotations.Text
20 |
21 | data
22 | public class TextObject(@Text val text: String)
23 |
--------------------------------------------------------------------------------
/parsnip/src/test/kotlin/me/tatarka/parsnip/samples/Rss.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Evan Tatarka.
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 me.tatarka.parsnip.samples
18 |
19 | import me.tatarka.parsnip.annotations.Namespace
20 | import me.tatarka.parsnip.annotations.SerializedName
21 | import me.tatarka.parsnip.annotations.Tag
22 |
23 | const val ATOM_NS: String = "http://www.w3.org/2005/Atom";
24 | const val ITUNES_NS: String = "http://www.itunes.com/dtds/podcast-1.0.dtd";
25 |
26 | data
27 | @SerializedName("rss")
28 | public class Rss(val channel: Channel)
29 |
30 | data
31 | public class Channel(
32 | @Namespace(ATOM_NS) val link: Link,
33 | @Tag val title: String,
34 | @Namespace(ITUNES_NS) val image: Image,
35 | @Tag val description: String,
36 | @Tag val author: String,
37 | @Tag val copyright: String
38 | )
39 |
40 | data
41 | public class Image(val href: String)
42 |
43 | data
44 | public class Link(val href: String)
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Evan Tatarka.
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 | include ':parsnip', ':parsnip-retrofit-converter', ':benchmark'
18 |
19 |
--------------------------------------------------------------------------------