@Test public void testJsonObject() throws Exception { String _json1 = "{o: {}}"; String _json2 = "{o: {o: {}}}"; String _json3 = "{o: {o: {f: 1}}}"; BsonDocument json1 = BsonDocument.parse(_json1); BsonDocument json2 = BsonDocument.parse(_json2); BsonDocument json3 = BsonDocument.parse(_json3); Assert.assertTrue(checkGetPropsFromPath(json1, "$.o", "{}")); Assert.assertTrue(checkGetPropsFromPath(json1, "$.*", "{}")); Assert.assertTrue(checkGetPropsFromPath(json1, "$.o.*")); Assert.assertTrue(checkGetPropsFromPath(json1, "$.o.*.f")); Assert.assertTrue(checkGetPropsFromPath(json2, "$.o", "{o: {}}")); Assert.assertTrue(checkGetPropsFromPath(json2, "$.*", "{o: {}}")); Assert.assertTrue(checkGetPropsFromPath(json2, "$.o.o", "{}")); Assert.assertTrue(checkGetPropsFromPath(json2, "$.o.*", "{}")); Assert.assertTrue(checkGetPropsFromPath(json2, "$.o.*.f", (String) null)); Assert.assertTrue(checkGetPropsFromPath(json3, "$.o", "{o: {f: 1}}")); Assert.assertTrue(checkGetPropsFromPath(json3, "$.*", "{o: {f: 1}}")); Assert.assertTrue(checkGetPropsFromPath(json3, "$.o.o", "{f: 1}")); Assert.assertTrue(checkGetPropsFromPath(json3, "$.o.*", "{f: 1}")); Assert.assertTrue(checkGetPropsFromPath(json3, "$.o.*.f", "1")); }
public static BsonValue parse(String json) throws JsonParseException { if (json == null) { return null; } String trimmed = json.trim(); if (trimmed.isEmpty()) { return null; } else if (trimmed.startsWith("{")) { try { return BsonDocument.parse(json); } catch (BsonInvalidOperationException ex) { return getBsonValue(json); } } else if (trimmed.startsWith("[")) { return BSON_ARRAY_CODEC.decode( new JsonReader(json), DecoderContext.builder().build()); } else { return getBsonValue(json); } }
JsonUtils { public static BsonValue parse(String json) throws JsonParseException { if (json == null) { return null; } String trimmed = json.trim(); if (trimmed.isEmpty()) { return null; } else if (trimmed.startsWith("{")) { try { return BsonDocument.parse(json); } catch (BsonInvalidOperationException ex) { return getBsonValue(json); } } else if (trimmed.startsWith("[")) { return BSON_ARRAY_CODEC.decode( new JsonReader(json), DecoderContext.builder().build()); } else { return getBsonValue(json); } } }
JsonUtils { public static BsonValue parse(String json) throws JsonParseException { if (json == null) { return null; } String trimmed = json.trim(); if (trimmed.isEmpty()) { return null; } else if (trimmed.startsWith("{")) { try { return BsonDocument.parse(json); } catch (BsonInvalidOperationException ex) { return getBsonValue(json); } } else if (trimmed.startsWith("[")) { return BSON_ARRAY_CODEC.decode( new JsonReader(json), DecoderContext.builder().build()); } else { return getBsonValue(json); } }  }
JsonUtils { public static BsonValue parse(String json) throws JsonParseException { if (json == null) { return null; } String trimmed = json.trim(); if (trimmed.isEmpty()) { return null; } else if (trimmed.startsWith("{")) { try { return BsonDocument.parse(json); } catch (BsonInvalidOperationException ex) { return getBsonValue(json); } } else if (trimmed.startsWith("[")) { return BSON_ARRAY_CODEC.decode( new JsonReader(json), DecoderContext.builder().build()); } else { return getBsonValue(json); } }  static BsonValue unescapeKeys(BsonValue json); static BsonValue escapeKeys(BsonValue json, boolean escapeDots); static List<Optional<BsonValue>> getPropsFromPath(
            BsonValue root,
            String path); static boolean isAncestorPath(final String left, final String right); static Integer countPropsFromPath(BsonValue root, String path); static boolean checkType(Optional<BsonValue> o, String type); static String minify(String jsonString); static BsonValue parse(String json); static String toJson(BsonValue bson); static String toJson(BsonValue bson, JsonMode mode); static String getIdAsString(BsonValue id, boolean quote); static BsonDocument toBsonDocument(Map<String, Object> map); static boolean isUpdateOperator(String key); static boolean containsUpdateOperators(BsonValue json); static boolean containsUpdateOperators(BsonValue json,
            boolean ignoreCurrentDate); static BsonValue unflatten(BsonValue json); static BsonDocument flatten(BsonDocument json, boolean ignoreUpdateOperators); }
JsonUtils { public static BsonValue parse(String json) throws JsonParseException { if (json == null) { return null; } String trimmed = json.trim(); if (trimmed.isEmpty()) { return null; } else if (trimmed.startsWith("{")) { try { return BsonDocument.parse(json); } catch (BsonInvalidOperationException ex) { return getBsonValue(json); } } else if (trimmed.startsWith("[")) { return BSON_ARRAY_CODEC.decode( new JsonReader(json), DecoderContext.builder().build()); } else { return getBsonValue(json); } }  static BsonValue unescapeKeys(BsonValue json); static BsonValue escapeKeys(BsonValue json, boolean escapeDots); static List<Optional<BsonValue>> getPropsFromPath(
            BsonValue root,
            String path); static boolean isAncestorPath(final String left, final String right); static Integer countPropsFromPath(BsonValue root, String path); static boolean checkType(Optional<BsonValue> o, String type); static String minify(String jsonString); static BsonValue parse(String json); static String toJson(BsonValue bson); static String toJson(BsonValue bson, JsonMode mode); static String getIdAsString(BsonValue id, boolean quote); static BsonDocument toBsonDocument(Map<String, Object> map); static boolean isUpdateOperator(String key); static boolean containsUpdateOperators(BsonValue json); static boolean containsUpdateOperators(BsonValue json,
            boolean ignoreCurrentDate); static BsonValue unflatten(BsonValue json); static BsonDocument flatten(BsonDocument json, boolean ignoreUpdateOperators);  }