-
-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e71754f
commit d7864b4
Showing
15 changed files
with
382 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package io.jooby.validation; | ||
|
||
import java.util.List; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
import java.util.stream.Collectors; | ||
|
||
public class JsonPointer { | ||
private static final Pattern ARRAY_PATTERN = Pattern.compile("(\\w+)\\[(\\d+)]"); | ||
|
||
public static String of(String propertyPath) { | ||
return toJsonPointer(propertyPath); | ||
} | ||
|
||
private static String toJsonPointer(String path) { | ||
if (path == null || path.isEmpty()) { | ||
return "/"; | ||
} | ||
|
||
List<String> parts = List.of(path.split("\\.")); | ||
|
||
return "/" + parts.stream() | ||
.map(JsonPointer::handleArrayIndex) | ||
.collect(Collectors.joining("/")); | ||
} | ||
|
||
private static String handleArrayIndex(String part) { | ||
Matcher matcher = ARRAY_PATTERN.matcher(part); | ||
if (matcher.matches()) { | ||
return matcher.group(1) + "/" + matcher.group(2); | ||
} | ||
return part; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.