Skip to content

Applying JSONPath filters on DocumentPatchBuilder produces FailedRequestException #161

@georgeajit

Description

@georgeajit

Here is a sample code that was used to tests replaceValue() on a JSON document:

public void testPartialUpdateReplaceValueJSON() throws IOException, JSONException
{
System.out.println("Running testPartialUpdateReplaceValueJSON");
String[] filenames = {"json-original.json"};
DatabaseClient client = DatabaseClientFactory.newClient("localhost", 8011, "rest-writer", "x", Authentication.DIGEST);
// write docs
for(String filename : filenames)
{
writeDocumentUsingInputStreamHandle(client, filename, "/partial-update/", "JSON");
}
String docId = "/partial-update/json-original.json";
JSONDocumentManager docMgr = client.newJSONDocumentManager();
DocumentPatchBuilder patchBldr = docMgr.newPatchBuilder();
patchBldr.pathLanguage(PathLanguage.JSONPATH);

    //Replace the third employee's first. Change it to Jack.
    patchBldr.replaceValue("$.employees[?(@.lastName==Foo)].firstName", "Jack");

    DocumentPatchHandle patchHandle = patchBldr.build();
    docMgr.patch(docId, patchHandle);

    String content = docMgr.read(docId, new StringHandle()).get();
    System.out.println(content);
    String exp="{\"employees\": [{\"firstName\":\"John\", \"lastName\":\"Doe\"}," +
               "{\"firstName\":\"Ann\", \"lastName\":\"Smith\"}," +
               "{\"firstName\":\"Jack\", \"lastName\":\"Foo\"}]}";
    JSONAssert.assertEquals(exp, content, false);

    // release client
    client.release();       
}

on this document:
{
"employees": [
{ "firstName":"John" , "lastName":"Doe" },
{ "firstName":"Ann" , "lastName":"Smith" },
{ "firstName":"Bob" , "lastName":"Foo" }
]
}

The patch function produces the following error. I tried the same document and filter using

http://ashphy.com/JSONPathOnlineEvaluator/ and http://jsonpath.curiousconcept.com/. These sites do not have trouble finding the object.

com.marklogic.client.FailedRequestException: Local message: write failed: Bad Request. Server Message: PARSE-EXPR (err:FOER0000): Failed to parse expression: Foo )] . firstName
at com.marklogic.client.impl.JerseyServices.putPostDocumentImpl(JerseyServices.java:1350)
at com.marklogic.client.impl.JerseyServices.patchDocument(JerseyServices.java:1522)
at com.marklogic.client.impl.DocumentManagerImpl.patch(DocumentManagerImpl.java:963)
at com.marklogic.client.impl.JSONDocumentImpl.patch(JSONDocumentImpl.java:26)
at com.marklogic.client.impl.DocumentManagerImpl.patch(DocumentManagerImpl.java:947)
at com.marklogic.client.impl.JSONDocumentImpl.patch(JSONDocumentImpl.java:26)
at com.marklogic.client.impl.DocumentManagerImpl.patch(DocumentManagerImpl.java:942)
at com.marklogic.client.impl.JSONDocumentImpl.patch(JSONDocumentImpl.java:26)
at com.marklogic.javaclient.TestPartialUpdate.testPartialUpdateReplaceValueJSON(TestPartialUpdate.java:879)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions