Skip to content

Commit d469886

Browse files
committed
Added jackson libraries with a custom failing test
added same test to gson to show it can handle the case I, Arne Osthues (arne.osthues@gmail.com, 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 d469886

File tree

12 files changed

+275
-9
lines changed

12 files changed

+275
-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: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
sourceCompatibility = 1.7
18+
targetCompatibility = 1.7
19+
20+
dependencies {
21+
compile project(':com.fasterxml.jackson.core-jackson-core')
22+
j2objcTranslation 'com.fasterxml.jackson.core:jackson-annotations:2.5.3:sources'
23+
}
24+
25+
j2objcConfig {
26+
autoConfigureDeps true
27+
28+
// Almost always there are no tests provided in an external source jar.
29+
testMinExpectedTests 0
30+
finalConfigure()
31+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
sourceCompatibility = 1.7
18+
targetCompatibility = 1.7
19+
20+
dependencies {
21+
j2objcTranslation 'com.fasterxml.jackson.core:jackson-core:2.5.3:sources'
22+
}
23+
24+
j2objcConfig {
25+
translateArgs '--segmented-headers' // import loops
26+
27+
testMinExpectedTests 0
28+
finalConfigure()
29+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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+
sourceCompatibility = 1.7
18+
targetCompatibility = 1.7
19+
20+
dependencies {
21+
compile project(':com.fasterxml.jackson.core-jackson-core')
22+
compile project(':com.fasterxml.jackson.core-jackson-annotations')
23+
compile 'com.fasterxml.jackson.core:jackson-databind:2.5.3'
24+
testCompile 'junit:junit:4.11'
25+
}
26+
27+
j2objcConfig {
28+
29+
translateArgs '--segmented-headers'
30+
translateArgs '--extract-unsequenced'
31+
32+
autoConfigureDeps true
33+
34+
translatePattern {
35+
exclude '**/fasterxml/jackson/databind/ext/DOMSerializer.java'
36+
}
37+
finalConfigure()
38+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
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.issues;
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 J2objcIssue639 {
29+
30+
private static String jsonValue = "{\n" +
31+
" \"addressList\": [\n" +
32+
" {\n" +
33+
" \"zipcode\": 12345,\n" +
34+
" \"street\": \"Stenhammer Drive\"\n" +
35+
" },\n" +
36+
" {\n" +
37+
" \"zipcode\": 7986,\n" +
38+
" \"street\": \"Market Street\"\n" +
39+
" }\n" +
40+
" ],\n" +
41+
" \"singleAddress\": {\n" +
42+
" \"zipcode\": 7986,\n" +
43+
" \"street\": \"Market Street\"\n" +
44+
" }\n" +
45+
"}" ;
46+
47+
@Test
48+
public void testMarshalling() throws IOException {
49+
Address homeAddress = new Address(12345, "Stenhammer Drive");
50+
Address workAddress = new Address(7986, "Market Street");
51+
ArrayList<Address> addressList = new ArrayList<>();
52+
addressList.add(homeAddress);
53+
addressList.add(workAddress);
54+
Person person = new Person(addressList);
55+
person.setSingleAddress(workAddress);
56+
57+
ObjectMapper objectMapper = new ObjectMapper();
58+
String value = objectMapper.writeValueAsString(person);
59+
60+
JsonNode expected = objectMapper.readTree(jsonValue);
61+
JsonNode actual = objectMapper.readTree(value);
62+
Assert.assertEquals(expected, actual);
63+
64+
}
65+
66+
@Test
67+
public void testDemarshallingWithEmbeddedObject() throws IOException {
68+
ObjectMapper objectMapper = new ObjectMapper();
69+
Person personValue = objectMapper.readValue(jsonValue, Person.class);
70+
Assert.assertTrue(personValue.getSingleAddress() instanceof Address);
71+
Assert.assertEquals(7986, personValue.singleAddress.zipcode);
72+
Assert.assertEquals("Market Street", personValue.singleAddress.street);
73+
}
74+
75+
@Test
76+
public void testDemarshallingListField() throws IOException {
77+
ObjectMapper objectMapper = new ObjectMapper();
78+
Person personValue = objectMapper.readValue(jsonValue, Person.class);
79+
80+
List<Address> addresses = personValue.getAddressList();
81+
Assert.assertEquals(2, addresses.size());
82+
Address firstAddress = addresses.get(0);
83+
Assert.assertTrue(firstAddress instanceof Address);
84+
85+
Assert.assertEquals(12345, firstAddress.zipcode);
86+
Assert.assertEquals("Stenhammer Drive", firstAddress.street);
87+
88+
}
89+
90+
public static class Person {
91+
92+
private ArrayList<Address> addressList;
93+
private Address singleAddress;
94+
95+
public Person(ArrayList<Address> addressList) {
96+
this.addressList = addressList;
97+
}
98+
99+
Person() {
100+
}
101+
102+
public List<Address> getAddressList() {
103+
return addressList;
104+
}
105+
106+
public void setAddressList(ArrayList<Address> addressList) {
107+
this.addressList = addressList;
108+
}
109+
110+
public Address getSingleAddress() {
111+
return singleAddress;
112+
}
113+
114+
public void setSingleAddress(Address singleAddress) {
115+
this.singleAddress = singleAddress;
116+
}
117+
}
118+
119+
public static class Address {
120+
121+
private int zipcode;
122+
private String street;
123+
124+
Address() {
125+
}
126+
127+
public Address(int zipcode,
128+
String street) {
129+
this.zipcode = zipcode;
130+
this.street = street;
131+
}
132+
133+
public int getZipcode() {
134+
return zipcode;
135+
}
136+
137+
public String getStreet() {
138+
return street;
139+
}
140+
141+
public void setZipcode(int zipcode) {
142+
this.zipcode = zipcode;
143+
}
144+
145+
public void setStreet(String street) {
146+
this.street = street;
147+
}
148+
}
149+
}
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)