Skip to content

Commit 63409f9

Browse files
committed
JAVA-1770: Deprecate com.mongodb.util.JSON and related classes
Applications should replace its use with JsonReader, JsonReader, and the toJson/parse methods on BasicDBObject that wrap them.
1 parent 691c7d9 commit 63409f9

File tree

12 files changed

+38
-15
lines changed

12 files changed

+38
-15
lines changed

driver/src/main/com/mongodb/BasicDBList.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
package com.mongodb;
2020

21-
import com.mongodb.util.JSON;
2221
import org.bson.types.BasicBSONList;
2322

2423
/**
@@ -34,8 +33,9 @@ public class BasicDBList extends BasicBSONList implements DBObject {
3433
* @return JSON serialization
3534
*/
3635
@Override
36+
@SuppressWarnings("deprecation")
3737
public String toString() {
38-
return JSON.serialize(this);
38+
return com.mongodb.util.JSON.serialize(this);
3939
}
4040

4141
@Override

driver/src/main/com/mongodb/BasicDBObject.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package com.mongodb;
1818

19-
import com.mongodb.util.JSON;
2019
import org.bson.BasicBSONObject;
2120
import org.bson.BsonDocument;
2221
import org.bson.BsonDocumentWrapper;
@@ -192,8 +191,9 @@ public String toJson(final JsonWriterSettings writerSettings, final Encoder<Basi
192191
*
193192
* @return JSON serialization
194193
*/
194+
@SuppressWarnings("deprecation")
195195
public String toString() {
196-
return JSON.serialize(this);
196+
return com.mongodb.util.JSON.serialize(this);
197197
}
198198

199199
/**

driver/src/main/com/mongodb/gridfs/GridFSFile.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import com.mongodb.BasicDBObject;
2020
import com.mongodb.DBObject;
2121
import com.mongodb.MongoException;
22-
import com.mongodb.util.JSON;
2322
import org.bson.BSONObject;
2423

2524
import java.util.Collections;
@@ -277,8 +276,9 @@ public void markAsPartialObject() {
277276
}
278277

279278
@Override
279+
@SuppressWarnings("deprecation")
280280
public String toString() {
281-
return JSON.serialize(this);
281+
return com.mongodb.util.JSON.serialize(this);
282282
}
283283

284284
/**

driver/src/main/com/mongodb/util/JSON.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2008-2014 MongoDB, Inc.
2+
* Copyright 2008-2017 MongoDB, Inc.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -14,15 +14,21 @@
1414
* limitations under the License.
1515
*/
1616

17-
// JSON.java
18-
1917
package com.mongodb.util;
2018

2119
import org.bson.BSONCallback;
2220

2321
/**
2422
* Helper methods for JSON serialization and de-serialization
23+
*
24+
* @see org.bson.json.JsonReader
25+
* @see org.bson.json.JsonWriter
26+
* @see com.mongodb.BasicDBObject#toJson()
27+
* @see com.mongodb.BasicDBObject#parse(String)
28+
*
29+
* @deprecated This class has been superseded by to toJson and parse methods on BasicDBObject
2530
*/
31+
@Deprecated
2632
public class JSON {
2733

2834
/**
@@ -133,6 +139,7 @@ class JSONParser {
133139
this(s, null);
134140
}
135141

142+
@SuppressWarnings("deprecation")
136143
JSONParser(final String s, final BSONCallback callback) {
137144
this.s = s;
138145
_callback = (callback == null) ? new JSONCallback() : callback;

driver/src/main/com/mongodb/util/JSONCallback.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@
4646

4747
/**
4848
* Converts JSON to DBObjects and vice versa.
49+
*
50+
* @deprecated This class has been superseded by to toJson and parse methods on BasicDBObject
4951
*/
52+
@Deprecated
5053
public class JSONCallback extends BasicBSONCallback {
5154

5255
@Override

driver/src/main/com/mongodb/util/JSONSerializers.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2008-2016 MongoDB, Inc.
2+
* Copyright 2008-2017 MongoDB, Inc.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -44,7 +44,15 @@
4444

4545
/**
4646
* Defines static methods for getting {@code ObjectSerializer} instances that produce various flavors of JSON.
47+
*
48+
* @see org.bson.json.JsonReader
49+
* @see org.bson.json.JsonWriter
50+
* @see com.mongodb.BasicDBObject#toJson()
51+
* @see com.mongodb.BasicDBObject#parse(String)
52+
*
53+
* @deprecated This class has been superseded by to toJson and parse methods on BasicDBObject
4754
*/
55+
@Deprecated
4856
public class JSONSerializers {
4957

5058
private JSONSerializers() {

driver/src/main/org/bson/BasicBSONObject.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package org.bson;
1818

19-
import com.mongodb.util.JSONSerializers;
2019
import org.bson.types.BasicBSONList;
2120
import org.bson.types.ObjectId;
2221

@@ -342,8 +341,9 @@ public BasicBSONObject append(final String key, final Object val) {
342341
* @return JSON serialization
343342
*/
344343
@Override
344+
@SuppressWarnings("deprecation")
345345
public String toString() {
346-
return JSONSerializers.getStrict().serialize(this);
346+
return com.mongodb.util.JSONSerializers.getStrict().serialize(this);
347347
}
348348

349349
/**

driver/src/main/org/bson/LazyBSONObject.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,7 @@ public boolean equals(final Object o) {
433433
*
434434
* @return JSON serialization
435435
*/
436+
@SuppressWarnings("deprecation")
436437
public String toString() {
437438
return com.mongodb.util.JSON.serialize(this);
438439
}

driver/src/test/unit/com/mongodb/BasicDBObjectTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package com.mongodb;
1818

19-
import com.mongodb.util.JSON;
2019
import org.bson.BasicBSONObject;
2120
import org.bson.json.JsonMode;
2221
import org.bson.json.JsonWriterSettings;
@@ -128,15 +127,17 @@ public void testBuilderIsEmpty() {
128127
}
129128

130129
@Test
130+
@SuppressWarnings("deprecation")
131131
public void testBuilderNested() {
132132
BasicDBObjectBuilder b = BasicDBObjectBuilder.start();
133133
b.add("a", 1);
134134
b.push("b").append("c", 2).pop();
135135
DBObject a = b.get();
136-
assertEquals(a, JSON.parse("{ 'a' : 1, 'b' : { 'c' : 2 } }"));
136+
assertEquals(a, com.mongodb.util.JSON.parse("{ 'a' : 1, 'b' : { 'c' : 2 } }"));
137137
}
138138

139139
@Test
140+
@SuppressWarnings("deprecation")
140141
public void testDown1() {
141142
BasicDBObjectBuilder b = BasicDBObjectBuilder.start();
142143
b.append("x", 1);
@@ -146,7 +147,7 @@ public void testDown1() {
146147
b.push("z");
147148
b.append("b", 3);
148149

149-
assertEquals(b.get(), JSON.parse("{ 'x' : 1 , 'y' : { 'a' : 2 } , 'z' : { 'b' : 3 } }"));
150+
assertEquals(b.get(), com.mongodb.util.JSON.parse("{ 'x' : 1 , 'y' : { 'a' : 2 } , 'z' : { 'b' : 3 } }"));
150151
}
151152

152153
@Test

driver/src/test/unit/com/mongodb/util/JSONCallbackTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import static org.junit.Assert.assertArrayEquals;
3838
import static org.junit.Assert.assertEquals;
3939

40+
@SuppressWarnings("deprecation")
4041
public class JSONCallbackTest {
4142

4243
@Test

0 commit comments

Comments
 (0)