Skip to content

Commit 513236f

Browse files
committed
Added jackson libraries with a custom failing test
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 513236f

File tree

12 files changed

+271
-4
lines changed

12 files changed

+271
-4
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: update of j2objc with this issue fixed: https://github.com/google/j2objc/issues/639
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+
j2objcTranslation 'com.fasterxml.jackson.core:jackson-databind:2.5.3:sources'
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,151 @@
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;
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 CoreJacksonDataBindMarshallingTest {
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+
// This test is expected to fail until j2objc is updated to a version where
76+
// this issue is fixed: https://github.com/google/j2objc/issues/639
77+
@Test
78+
public void testDemarshallingListField() throws IOException {
79+
ObjectMapper objectMapper = new ObjectMapper();
80+
Person personValue = objectMapper.readValue(jsonValue, Person.class);
81+
82+
List<Address> addresses = personValue.getAddressList();
83+
Assert.assertEquals(2, addresses.size());
84+
Address firstAddress = addresses.get(0);
85+
Assert.assertTrue(firstAddress instanceof Address);
86+
87+
Assert.assertEquals(12345, firstAddress.zipcode);
88+
Assert.assertEquals("Stenhammer Drive", firstAddress.street);
89+
90+
}
91+
92+
public static class Person {
93+
94+
private ArrayList<Address> addressList;
95+
private Address singleAddress;
96+
97+
public Person(ArrayList<Address> addressList) {
98+
this.addressList = addressList;
99+
}
100+
101+
Person() {
102+
}
103+
104+
public List<Address> getAddressList() {
105+
return addressList;
106+
}
107+
108+
public void setAddressList(ArrayList<Address> addressList) {
109+
this.addressList = addressList;
110+
}
111+
112+
public Address getSingleAddress() {
113+
return singleAddress;
114+
}
115+
116+
public void setSingleAddress(Address singleAddress) {
117+
this.singleAddress = singleAddress;
118+
}
119+
}
120+
121+
public static class Address {
122+
123+
private int zipcode;
124+
private String street;
125+
126+
Address() {
127+
}
128+
129+
public Address(int zipcode,
130+
String street) {
131+
this.zipcode = zipcode;
132+
this.street = street;
133+
}
134+
135+
public int getZipcode() {
136+
return zipcode;
137+
}
138+
139+
public String getStreet() {
140+
return street;
141+
}
142+
143+
public void setZipcode(int zipcode) {
144+
this.zipcode = zipcode;
145+
}
146+
147+
public void setStreet(String street) {
148+
this.street = street;
149+
}
150+
}
151+
}
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)