Skip to content

Commit 087f6e4

Browse files
committed
Added jackson libraries with a custom failing test
added same test to gson to show it can handle the case
1 parent b216e41 commit 087f6e4

File tree

13 files changed

+505
-2
lines changed

13 files changed

+505
-2
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
.gradle
22
build/
3+
*.iml
4+
\.idea/
35

46
# Ignore Gradle GUI config
57
gradle-app.setting

.travis.yml

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