Skip to content

Commit 6fff077

Browse files
committed
move Jackson from extra to io since ML 8 makes JSON a native datatype
1 parent b1c2f3e commit 6fff077

File tree

5 files changed

+87
-4
lines changed

5 files changed

+87
-4
lines changed

src/main/java/com/marklogic/client/example/handle/JacksonHandleExample.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import com.marklogic.client.document.JSONDocumentManager;
2828
import com.marklogic.client.example.cookbook.Util;
2929
import com.marklogic.client.example.cookbook.Util.ExampleProperties;
30-
import com.marklogic.client.extra.jackson.JacksonHandle;
30+
import com.marklogic.client.io.JacksonHandle;
3131

3232
/**
3333
* JacksonHandleExample illustrates writing and reading content as a JSON structure

src/main/java/com/marklogic/client/impl/FailedRequest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import org.w3c.dom.Document;
2727
import org.xml.sax.SAXException;
2828

29-
import com.marklogic.client.extra.jackson.JSONErrorParser;
29+
import com.marklogic.client.io.JSONErrorParser;
3030

3131
/**
3232
* Encapsulate data passed in an error response from a REST server instance

src/main/java/com/marklogic/client/io/JSONErrorParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.marklogic.client.extra.jackson;
1+
package com.marklogic.client.io;
22

33
import java.io.IOException;
44
import java.io.InputStream;

src/main/java/com/marklogic/client/io/JacksonHandle.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package com.marklogic.client.extra.jackson;
16+
package com.marklogic.client.io;
1717

1818
import java.io.ByteArrayInputStream;
1919
import java.io.ByteArrayOutputStream;
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
* Copyright 2012-2014 MarkLogic Corporation
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 com.marklogic.client.test;
17+
18+
import static org.junit.Assert.assertNotNull;
19+
import static org.junit.Assert.assertTrue;
20+
21+
import org.junit.AfterClass;
22+
import org.junit.BeforeClass;
23+
import org.junit.Test;
24+
25+
import com.fasterxml.jackson.databind.JsonNode;
26+
import com.fasterxml.jackson.databind.ObjectMapper;
27+
import com.fasterxml.jackson.databind.node.ArrayNode;
28+
import com.fasterxml.jackson.databind.node.ObjectNode;
29+
import com.marklogic.client.document.JSONDocumentManager;
30+
import com.marklogic.client.io.JacksonHandle;
31+
import com.marklogic.client.test.Common;
32+
33+
public class JacksonHandleTest {
34+
@BeforeClass
35+
public static void beforeClass() {
36+
Common.connect();
37+
}
38+
@AfterClass
39+
public static void afterClass() {
40+
Common.release();
41+
}
42+
43+
@Test
44+
public void testReadWrite() {
45+
// create an identifier for the database document
46+
String docId = "/example/jackson-test.json";
47+
48+
// create a manager for JSON documents
49+
JSONDocumentManager docMgr = Common.client.newJSONDocumentManager();
50+
51+
// construct a Jackson JSON structure
52+
ObjectMapper mapper = new ObjectMapper();
53+
ObjectNode childObj = mapper.createObjectNode();
54+
childObj.put("key", "value");
55+
ArrayNode childArray = mapper.createArrayNode();
56+
childArray.add("item1");
57+
childArray.add("item2");
58+
ObjectNode writeRoot = mapper.createObjectNode();
59+
writeRoot.put("object", childObj);
60+
writeRoot.put("array", childArray);
61+
62+
// create a handle for the JSON structure
63+
JacksonHandle writeHandle = new JacksonHandle(writeRoot);
64+
65+
// write the document to the database
66+
docMgr.write(docId, writeHandle);
67+
68+
// create a handle to receive the database content as a Jackson structure
69+
JacksonHandle readHandle = new JacksonHandle();
70+
71+
// read the document content from the database as a Jackson structure
72+
docMgr.read(docId, readHandle);
73+
74+
// access the document content
75+
JsonNode readRoot = readHandle.get();
76+
assertNotNull("Wrote null Jackson JSON structure", readRoot);
77+
assertTrue("Jackson JSON structures not equal",
78+
readRoot.equals(writeRoot));
79+
80+
// delete the document
81+
docMgr.delete(docId);
82+
}
83+
}

0 commit comments

Comments
 (0)