generated from hmcts/spring-boot-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PO-559: Updates to 'broken' Draft Accounts POST endpoint
- Loading branch information
1 parent
081e179
commit 7202a86
Showing
6 changed files
with
72 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package uk.gov.hmcts.opal.util; | ||
|
||
import com.jayway.jsonpath.Configuration; | ||
import com.jayway.jsonpath.DocumentContext; | ||
import com.jayway.jsonpath.JsonPath; | ||
import com.jayway.jsonpath.Option; | ||
import com.jayway.jsonpath.PathNotFoundException; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@Slf4j(topic = "JsonPathUtil") | ||
public class JsonPathUtil { | ||
|
||
public static DocContext createDocContext(String document) { | ||
Configuration config = Configuration.defaultConfiguration().addOptions(Option.DEFAULT_PATH_LEAF_TO_NULL); | ||
return new DocContext(JsonPath.parse(document, config), document); | ||
} | ||
|
||
public static class DocContext { | ||
private final DocumentContext documentContext; | ||
private final String originalDocument; | ||
|
||
public DocContext(DocumentContext documentContext, String originalDocument) { | ||
this.documentContext = documentContext; | ||
this.originalDocument = originalDocument; | ||
} | ||
|
||
public <T> T read(String path) { | ||
try { | ||
return documentContext.read(path); | ||
} catch (PathNotFoundException pnfe) { | ||
// All this is required because the PathNotFoundException suppresses the Stack Trace. | ||
throw new RuntimeException(pnfe.getMessage()); | ||
} | ||
} | ||
} | ||
} |
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