1414 * @author petruki
1515 * @since 2025-08-02
1616 */
17- @ SuppressWarnings ("unchecked" )
1817public class DotPathQL {
1918
2019 private final DotPath pathFilter ;
@@ -59,65 +58,6 @@ public <T> Map<String, Object> exclude(T source, List<String> excludePaths) {
5958 return pathExclude .run (source , excludePaths );
6059 }
6160
62- /**
63- * Converts the source object to a map representation.
64- *
65- * @param <T> the type of the source object
66- * @param source the source object to convert
67- * @return a map containing all properties of the source object
68- */
69- public <T > Map <String , Object > toMap (T source ) {
70- return exclude (source , Collections .emptyList ());
71- }
72-
73- /**
74- * Extracts a map from the source map based on the specified property.
75- *
76- * @param source the source map
77- * @param property the property to extract
78- * @return the extracted map or an empty map if not found
79- * @throws ClassCastException if the property is not a map
80- */
81- public Map <String , Object > mapFrom (Map <String , Object > source , String property ) {
82- if (isInvalid (source , property )) {
83- return Collections .emptyMap ();
84- }
85-
86- return (Map <String , Object >) source .get (property );
87- }
88-
89- /**
90- * Extracts a list of maps from the source map based on the specified property.
91- *
92- * @param source the source map
93- * @param property the property to extract
94- * @return the extracted list of maps or an empty list if not found
95- * @throws ClassCastException if the property is not a list of maps
96- */
97- public List <Map <String , Object >> listFrom (Map <String , Object > source , String property ) {
98- if (isInvalid (source , property )) {
99- return Collections .emptyList ();
100- }
101-
102- return (List <Map <String , Object >>) source .get (property );
103- }
104-
105- /**
106- * Extracts a list of objects from the source map based on the specified property.
107- *
108- * @param source the source map
109- * @param property the property to extract
110- * @return the extracted list of objects or an empty list if not found
111- * @throws ClassCastException if the property is not a list of objects
112- */
113- public Object [] arrayFrom (Map <String , Object > source , String property ) {
114- if (isInvalid (source , property )) {
115- return new Object [0 ];
116- }
117-
118- return (Object []) source .get (property );
119- }
120-
12161 /**
12262 * Adds default filter paths that will be included in every filtering operation.
12363 *
@@ -136,6 +76,17 @@ public void addDefaultExcludePaths(List<String> paths) {
13676 pathExclude .addDefaultPaths (paths );
13777 }
13878
79+ /**
80+ * Converts the source object to a map representation.
81+ *
82+ * @param <T> the type of the source object
83+ * @param source the source object to convert
84+ * @return a map containing all properties of the source object
85+ */
86+ public <T > Map <String , Object > toMap (T source ) {
87+ return exclude (source , Collections .emptyList ());
88+ }
89+
13990 /**
14091 * Converts the given sourceMap to a JSON string representation with optional formatting.
14192 *
@@ -159,7 +110,4 @@ public String toJson(Map<String, Object> sourceMap, boolean prettier) {
159110 return pathPrinter .toJson (sourceMap , prettier );
160111 }
161112
162- private boolean isInvalid (Map <String , Object > source , String property ) {
163- return source == null || property == null || property .isEmpty () || !source .containsKey (property );
164- }
165113}
0 commit comments