Skip to content

Commit 30da242

Browse files
saruyemarketing@fileee.com
authored andcommitted
Added jackson libraries with a custom failing test
added same test to gson to show it can handle the case I, Arne Osthues ([email protected], https://github.com/saruye), certify that a) this Contribution is my original work, and b) I have the right to submit this Contribution under the Apache License, Version 2.0 (the "License") available at http://www.apache.org/licenses/LICENSE-2.0, and c) I am submitting this Contribution under the License.
1 parent d71f3b0 commit 30da242

File tree

12 files changed

+332
-9
lines changed

12 files changed

+332
-9
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
# Build
66
build/
7+
*.iml
8+
\.idea/
79

810
# Ignore Gradle GUI config
911
gradle-app.setting

.travis.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,15 @@ env:
1313
- TEST_DIR=joda-time-joda-time
1414
- TEST_DIR=org.joda-joda-primitives
1515
- TEST_DIR=org.apache.commons-commons-lang3
16+
- TEST_DIR=com.fasterxml.jackson.core
1617

1718
# Uncomment to add a library that should fail to build, along with documentation on why.
18-
# matrix:
19-
# allow_failures:
20-
# # Blocked on (github issue url)
21-
# - env: TEST_DIR=libraryBuilds/com.example-library
19+
matrix:
20+
allow_failures:
21+
# Blocked on (github issue url)
22+
# - env: TEST_DIR=com.example-library
23+
# Blocked on: https://github.com/j2objc-contrib/j2objc-common-libs-e2e-test/issues/48
24+
- env: TEST_DIR=com.fasterxml.jackson.core
2225

2326
branches:
2427
only:
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../common/build.gradle
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright (c) 2015 the authors of j2objc-common-libs-e2e-test
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+
dependencies {
18+
compile project(':com.fasterxml.jackson.core-jackson-core')
19+
j2objcTranslation 'com.fasterxml.jackson.core:jackson-annotations:2.5.3:sources'
20+
}
21+
22+
j2objcConfig {
23+
autoConfigureDeps true
24+
25+
// Almost always there are no tests provided in an external source jar.
26+
testMinExpectedTests 0
27+
finalConfigure()
28+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright (c) 2015 the authors of j2objc-common-libs-e2e-test
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+
dependencies {
18+
j2objcTranslation 'com.fasterxml.jackson.core:jackson-core:2.5.3:sources'
19+
}
20+
21+
j2objcConfig {
22+
translateArgs '--segmented-headers' // import loops
23+
24+
testMinExpectedTests 0
25+
finalConfigure()
26+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright (c) 2015 the authors of j2objc-common-libs-e2e-test
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+
dependencies {
18+
compile project(':com.fasterxml.jackson.core-jackson-core')
19+
compile project(':com.fasterxml.jackson.core-jackson-annotations')
20+
j2objcTranslation 'com.fasterxml.jackson.core:jackson-databind:2.5.3:sources'
21+
testCompile 'junit:junit:4.11'
22+
}
23+
24+
j2objcConfig {
25+
26+
translateArgs '--segmented-headers'
27+
translateArgs '--extract-unsequenced'
28+
29+
autoConfigureDeps true
30+
31+
translatePattern {
32+
exclude '**/fasterxml/jackson/databind/ext/DOMSerializer.java'
33+
}
34+
finalConfigure()
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
/*
2+
* Copyright (c) 2015 the authors of j2objc-common-libs-e2e-test
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.github.j2objccontrib.j2objcgradle.failing;
18+
19+
import com.fasterxml.jackson.databind.JsonNode;
20+
import com.fasterxml.jackson.databind.ObjectMapper;
21+
import org.junit.Assert;
22+
import org.junit.Test;
23+
24+
import java.io.IOException;
25+
import java.util.ArrayList;
26+
import java.util.List;
27+
28+
public class GenericsTest {
29+
public static class Person {
30+
31+
private String name;
32+
private String lastName;
33+
private int age;
34+
private ArrayList<Address> addressList;
35+
private Address singleAddress;
36+
37+
public Person(String name,
38+
String lastName,
39+
int age,
40+
ArrayList<Address> addressList) {
41+
this.name = name;
42+
this.lastName = lastName;
43+
this.age = age;
44+
this.addressList = addressList;
45+
}
46+
47+
Person() {
48+
}
49+
50+
@Override
51+
public String toString() {
52+
StringBuilder stringBuilder = new StringBuilder();
53+
stringBuilder.append("name: ")
54+
.append(this.name).append("\n")
55+
.append("lastName: ")
56+
.append(this.lastName).append("\n")
57+
.append("age: ")
58+
.append(this.age).append("\n");
59+
60+
for (Address address : this.addressList) {
61+
stringBuilder.append(address.toString());
62+
}
63+
64+
return stringBuilder.toString();
65+
}
66+
67+
public String getName() {
68+
return name;
69+
}
70+
71+
public String getLastName() {
72+
return lastName;
73+
}
74+
75+
public int getAge() {
76+
return age;
77+
}
78+
79+
public List<Address> getAddressList() {
80+
return addressList;
81+
}
82+
83+
public void setName(String name) {
84+
this.name = name;
85+
}
86+
87+
public void setLastName(String lastName) {
88+
this.lastName = lastName;
89+
}
90+
91+
public void setAge(int age) {
92+
this.age = age;
93+
}
94+
95+
public void setAddressList(ArrayList<Address> addressList) {
96+
this.addressList = addressList;
97+
}
98+
99+
public Address getSingleAddress() {
100+
return singleAddress;
101+
}
102+
103+
public void setSingleAddress(Address singleAddress) {
104+
this.singleAddress = singleAddress;
105+
}
106+
}
107+
108+
public static class Address {
109+
110+
private int zipcode;
111+
private String street;
112+
113+
Address() {
114+
115+
}
116+
117+
public Address(int zipcode,
118+
String street) {
119+
this.zipcode = zipcode;
120+
this.street = street;
121+
}
122+
123+
@Override
124+
public String toString() {
125+
StringBuilder stringBuilder = new StringBuilder();
126+
stringBuilder.append("zipcode: ")
127+
.append(this.zipcode).append("\n")
128+
.append("street: ")
129+
.append(this.street).append("\n");
130+
131+
return stringBuilder.toString();
132+
}
133+
134+
public int getZipcode() {
135+
return zipcode;
136+
}
137+
138+
public String getStreet() {
139+
return street;
140+
}
141+
142+
public void setZipcode(int zipcode) {
143+
this.zipcode = zipcode;
144+
}
145+
146+
public void setStreet(String street) {
147+
this.street = street;
148+
}
149+
}
150+
151+
@Test
152+
public void testMarshalling() throws IOException {
153+
Address homeAddress = new Address(12345, "Stenhammer Drive");
154+
Address workAddress = new Address(7986, "Market Street");
155+
ArrayList<Address> addressList = new ArrayList<>();
156+
addressList.add(homeAddress);
157+
addressList.add(workAddress);
158+
Person person = new Person("Sawyer", "Bootstrapper", 23, addressList);
159+
person.setSingleAddress(workAddress);
160+
161+
ObjectMapper objectMapper = new ObjectMapper();
162+
String value = objectMapper.writeValueAsString(person);
163+
164+
JsonNode expected = objectMapper.readTree(jsonValue);
165+
JsonNode actual = objectMapper.readTree(value);
166+
Assert.assertEquals(expected, actual);
167+
168+
}
169+
170+
private static String jsonValue = "{\"name\":\"Sawyer\",\"lastName\":\"Bootstrapper\",\"age\":23,\"addressList\":[{\"zipcode\":12345,\"street\":" +
171+
"\"Stenhammer Drive\"},{\"zipcode\":7986,\"street\":\"Market Street\"}],\"singleAddress\":{\"zipcode\":7986,\"street\":\"Market Street\"}}";
172+
173+
174+
@Test
175+
public void testDemarshallingWithEmbeddedObject() throws IOException {
176+
ObjectMapper objectMapper = new ObjectMapper();
177+
Person personValue = objectMapper.readValue(jsonValue, Person.class);
178+
Assert.assertTrue(personValue.getSingleAddress() instanceof Address);
179+
Assert.assertEquals(7986, personValue.singleAddress.zipcode);
180+
Assert.assertEquals("Market Street", personValue.singleAddress.street);
181+
}
182+
183+
@Test
184+
public void testDemarshallingSimpleFields() throws IOException {
185+
ObjectMapper objectMapper = new ObjectMapper();
186+
Person personValue = objectMapper.readValue(jsonValue, Person.class);
187+
188+
Assert.assertEquals("Sawyer", personValue.name);
189+
Assert.assertEquals("Bootstrapper", personValue.lastName);
190+
Assert.assertEquals(23, personValue.age);
191+
192+
}
193+
194+
@Test
195+
public void testDemarshallingListField() throws IOException {
196+
ObjectMapper objectMapper = new ObjectMapper();
197+
Person personValue = objectMapper.readValue(jsonValue, Person.class);
198+
199+
List<Address> addresses = personValue.addressList;
200+
Assert.assertEquals(2, addresses.size());
201+
Address firstAddress = addresses.get(0);
202+
Assert.assertTrue(firstAddress instanceof Address);
203+
204+
Assert.assertEquals(12345, firstAddress.zipcode);
205+
Assert.assertEquals("Stenhammer Drive", firstAddress.street);
206+
System.out.println("demarhsalling works");
207+
208+
}
209+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../j2objc-gradle/gradlew
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../common/local.properties
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include ':com.fasterxml.jackson.core-jackson-core',':com.fasterxml.jackson.core-jackson-annotations',':com.fasterxml.jackson.core-jackson-databind'

0 commit comments

Comments
 (0)