Skip to content

Commit

Permalink
Merge pull request Azure#38 from chetanmeh/remove-org-json
Browse files Browse the repository at this point in the history
Replace org.json usage with Jackson
  • Loading branch information
Srinath Narayanan committed May 18, 2018
2 parents 707efab + 5fc5809 commit aa5e4c3
Show file tree
Hide file tree
Showing 50 changed files with 446 additions and 317 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public void testUpdateOffer() throws Exception {

// This offer must correspond to the collection we created
Offer offer = offerList.get(0);
int curentThroughput = offer.getContent().getInt("offerThroughput");
int curentThroughput = offer.getContent().get("offerThroughput").asInt();
assertThat(offer.getString("offerResourceId"), equalTo(createdCollection.getResourceId()));
assertThat(curentThroughput, equalTo(initialThroughput));
System.out.println("initial throughput: " + curentThroughput);
Expand All @@ -136,7 +136,7 @@ public void testUpdateOffer() throws Exception {
return asyncClient.replaceOffer(offer);
}).subscribe(offerResourceResponse -> {
Offer offer = offerResourceResponse.getResource();
int curentThroughput = offer.getContent().getInt("offerThroughput");
int curentThroughput = offer.getContent().get("offerThroughput").asInt();

// The current throughput of the offer must be equal to the new throughput value
assertThat(offer.getString("offerResourceId"), equalTo(createdCollection.getResourceId()));
Expand Down
5 changes: 0 additions & 5 deletions sdk/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,6 @@ SOFTWARE.
<artifactId>java-uuid-generator</artifactId>
<version>3.1.4</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20140107</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@

package com.microsoft.azure.cosmosdb;

import org.json.JSONObject;

import com.fasterxml.jackson.databind.node.ObjectNode;
import com.microsoft.azure.cosmosdb.internal.Constants;

/**
Expand Down Expand Up @@ -57,7 +56,7 @@ public Attachment(String source) {
*
* @param jsonObject the json object representation of the Attachment.
*/
public Attachment(JSONObject jsonObject) {
public Attachment(ObjectNode jsonObject) {
super(jsonObject);
}

Expand Down
4 changes: 2 additions & 2 deletions sdk/src/main/java/com/microsoft/azure/cosmosdb/Conflict.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

package com.microsoft.azure.cosmosdb;

import org.json.JSONObject;
import com.fasterxml.jackson.databind.node.ObjectNode;

import com.microsoft.azure.cosmosdb.internal.Constants;

Expand Down Expand Up @@ -56,7 +56,7 @@ public Conflict(String jsonString) {
*
* @param jsonObject the json object that represents the conflict.
*/
public Conflict(JSONObject jsonObject) {
public Conflict(ObjectNode jsonObject) {
super(jsonObject);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@


import org.apache.commons.lang3.text.WordUtils;
import org.json.JSONObject;
import com.fasterxml.jackson.databind.node.ObjectNode;

import com.microsoft.azure.cosmosdb.internal.Constants;

Expand Down Expand Up @@ -61,7 +61,7 @@ public ConsistencyPolicy(String jsonString) {
*
* @param jsonObject the json object that represents the consistency policy.
*/
public ConsistencyPolicy(JSONObject jsonObject) {
public ConsistencyPolicy(ObjectNode jsonObject) {
super(jsonObject);
}

Expand Down
4 changes: 2 additions & 2 deletions sdk/src/main/java/com/microsoft/azure/cosmosdb/Database.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@

package com.microsoft.azure.cosmosdb;

import com.fasterxml.jackson.databind.node.ObjectNode;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONObject;

import com.microsoft.azure.cosmosdb.internal.Constants;

Expand Down Expand Up @@ -60,7 +60,7 @@ public Database(String jsonString) {
*
* @param jsonObject the json object.
*/
public Database(JSONObject jsonObject) {
public Database(ObjectNode jsonObject) {
super(jsonObject);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

package com.microsoft.azure.cosmosdb;

import org.json.JSONObject;
import com.fasterxml.jackson.databind.node.ObjectNode;

import com.microsoft.azure.cosmosdb.internal.Constants;

Expand Down Expand Up @@ -59,7 +59,7 @@ public DatabaseAccount(String jsonString) {
*
* @param jsonObject the json object that represents the database account.
*/
public DatabaseAccount(JSONObject jsonObject) {
public DatabaseAccount(ObjectNode jsonObject) {
super(jsonObject);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

package com.microsoft.azure.cosmosdb;

import org.json.JSONObject;
import com.fasterxml.jackson.databind.node.ObjectNode;

import com.microsoft.azure.cosmosdb.internal.Constants;

Expand Down Expand Up @@ -57,7 +57,7 @@ public DatabaseAccountLocation(String jsonString) {
*
* @param jsonObject the JSON object that represents the DatabaseAccountLocation object.
*/
public DatabaseAccountLocation(JSONObject jsonObject) {
public DatabaseAccountLocation(ObjectNode jsonObject) {
super(jsonObject);
}

Expand Down
5 changes: 2 additions & 3 deletions sdk/src/main/java/com/microsoft/azure/cosmosdb/Document.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@

import java.io.IOException;

import org.json.JSONObject;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.microsoft.azure.cosmosdb.internal.Constants;

/**
Expand Down Expand Up @@ -71,7 +70,7 @@ public Document(String jsonString) {
*
* @param jsonObject the json object that represents the document object.
*/
public Document(JSONObject jsonObject) {
public Document(ObjectNode jsonObject) {
super(jsonObject);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
package com.microsoft.azure.cosmosdb;

import org.apache.commons.lang3.StringUtils;
import org.json.JSONObject;
import com.fasterxml.jackson.databind.node.ObjectNode;

import com.microsoft.azure.cosmosdb.internal.Constants;

Expand Down Expand Up @@ -62,7 +62,7 @@ public DocumentCollection(String jsonString) {
*
* @param jsonObject the json object that represents the document collection.
*/
public DocumentCollection(JSONObject jsonObject) {
public DocumentCollection(ObjectNode jsonObject) {
super(jsonObject);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

package com.microsoft.azure.cosmosdb;

import org.json.JSONObject;
import com.fasterxml.jackson.databind.node.ObjectNode;

import com.microsoft.azure.cosmosdb.internal.Constants;

Expand Down Expand Up @@ -54,7 +54,7 @@ public ExcludedPath(String jsonString) {
*
* @param jsonObject the json object that represents the excluded path.
*/
public ExcludedPath(JSONObject jsonObject) {
public ExcludedPath(ObjectNode jsonObject) {
super(jsonObject);
}

Expand Down
4 changes: 2 additions & 2 deletions sdk/src/main/java/com/microsoft/azure/cosmosdb/HashIndex.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
package com.microsoft.azure.cosmosdb;

import org.apache.commons.lang3.text.WordUtils;
import org.json.JSONObject;
import com.fasterxml.jackson.databind.node.ObjectNode;

import com.microsoft.azure.cosmosdb.internal.Constants;

Expand Down Expand Up @@ -91,7 +91,7 @@ public HashIndex(String jsonString) {
*
* @param jsonObject the json object that represents the index.
*/
public HashIndex(JSONObject jsonObject) {
public HashIndex(ObjectNode jsonObject) {
super(jsonObject, IndexKind.Hash);
if (this.getDataType() == null) {
throw new IllegalArgumentException("The jsonObject doesn't contain a valid 'dataType'.");
Expand Down
15 changes: 8 additions & 7 deletions sdk/src/main/java/com/microsoft/azure/cosmosdb/IncludedPath.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@
import java.util.ArrayList;
import java.util.Collection;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ArrayNode;
import org.apache.commons.lang3.text.WordUtils;
import org.json.JSONArray;
import org.json.JSONObject;
import com.fasterxml.jackson.databind.node.ObjectNode;

import com.microsoft.azure.cosmosdb.internal.Constants;

Expand Down Expand Up @@ -61,7 +62,7 @@ public IncludedPath(String jsonString) {
*
* @param jsonObject the json object that represents the included path.
*/
public IncludedPath(JSONObject jsonObject) {
public IncludedPath(ObjectNode jsonObject) {
super(jsonObject);
}

Expand Down Expand Up @@ -106,14 +107,14 @@ public void setIndexes(Collection<Index> indexes) {

private Collection<Index> getIndexCollection() {
if (this.propertyBag != null && this.propertyBag.has(Constants.Properties.INDEXES)) {
JSONArray jsonArray = this.propertyBag.getJSONArray(Constants.Properties.INDEXES);
ArrayNode jsonArray = (ArrayNode) this.propertyBag.get(Constants.Properties.INDEXES);
Collection<Index> result = new ArrayList<Index>();

for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonObject = jsonArray.getJSONObject(i);
for (int i = 0; i < jsonArray.size(); i++) {
JsonNode jsonObject = jsonArray.get(i);

IndexKind indexKind = IndexKind.valueOf(WordUtils.capitalize(
jsonObject.getString(Constants.Properties.INDEX_KIND)));
jsonObject.get(Constants.Properties.INDEX_KIND).asText()));
switch (indexKind) {
case Hash:
result.add(new HashIndex(jsonObject.toString()));
Expand Down
4 changes: 2 additions & 2 deletions sdk/src/main/java/com/microsoft/azure/cosmosdb/Index.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
package com.microsoft.azure.cosmosdb;

import org.apache.commons.lang3.text.WordUtils;
import org.json.JSONObject;
import com.fasterxml.jackson.databind.node.ObjectNode;

import com.microsoft.azure.cosmosdb.internal.Constants;

Expand Down Expand Up @@ -61,7 +61,7 @@ protected Index(String jsonString, IndexKind indexKind) {
* @param jsonObject the json object that represents the index.
* @param indexKind the kind of the index
*/
protected Index(JSONObject jsonObject, IndexKind indexKind) {
protected Index(ObjectNode jsonObject, IndexKind indexKind) {
super(jsonObject);
this.setKind(indexKind);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import java.util.Collection;

import org.apache.commons.lang3.text.WordUtils;
import org.json.JSONObject;
import com.fasterxml.jackson.databind.node.ObjectNode;

import com.microsoft.azure.cosmosdb.internal.Constants;

Expand Down Expand Up @@ -104,7 +104,7 @@ public IndexingPolicy(String jsonString) {
*
* @param jsonObject the json object that represents the indexing policy.
*/
public IndexingPolicy(JSONObject jsonObject) {
public IndexingPolicy(ObjectNode jsonObject) {
super(jsonObject);
}

Expand Down
Loading

0 comments on commit aa5e4c3

Please sign in to comment.