Skip to content

Commit ddb7e2f

Browse files
Bug fix. Releasing new version
1 parent 5233ecf commit ddb7e2f

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/main/java/org/burningwave/json/ObjectHandler.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
import java.util.function.Function;
4141
import java.util.function.Predicate;
4242
import java.util.function.Supplier;
43+
import java.util.regex.Matcher;
44+
import java.util.regex.Pattern;
4345
import java.util.stream.Collectors;
4446
import java.util.stream.Stream;
4547

@@ -53,6 +55,9 @@
5355

5456
@SuppressWarnings("unchecked")
5557
public class ObjectHandler {
58+
59+
private final static Pattern INDEXES_SEARCHER_FOR_INDEXED_FIELD;
60+
5661
private static Function<ObjectHandler, Object> valueRetriever;
5762
static {
5863
try {
@@ -66,6 +71,7 @@ public class ObjectHandler {
6671
valueRetriever = buildAlwaysNullVaueIfNotValorizedRetriever();
6772
}
6873
}
74+
INDEXES_SEARCHER_FOR_INDEXED_FIELD = Pattern.compile("\\[(.*?)\\]");
6975
}
7076

7177
static Function<ObjectHandler, Object> buildValueRetriever(
@@ -78,7 +84,15 @@ static Function<ObjectHandler, Object> buildValueRetriever(
7884
break;
7985
}
8086
if (value instanceof Map) {
81-
pathSegment = "[" + pathSegment + "]";
87+
Matcher matcher = INDEXES_SEARCHER_FOR_INDEXED_FIELD.matcher(pathSegment);
88+
String index = "";
89+
if (matcher.find()) {
90+
index = matcher.group(0);
91+
}
92+
if (!index.isEmpty()) {
93+
pathSegment = pathSegment.replace(index, "");
94+
}
95+
pathSegment = "[" + pathSegment + "]" + index;
8296
}
8397
try {
8498
value = fieldAccessor.get(value, pathSegment);

0 commit comments

Comments
 (0)