Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NullPointerException with JSON containing empty object using deep scanning path using JsonOrgJsonProvider. #497

Closed
DavidAmmeraal opened this issue Sep 10, 2018 · 1 comment

Comments

@DavidAmmeraal
Copy link

This throws a NullPointerException when I'm using the JsonOrgJsonProvider. Using the default provider and mapper it works fine.

import com.jayway.jsonpath.Configuration;
import com.jayway.jsonpath.JsonPath;
import com.jayway.jsonpath.spi.json.JsonOrgJsonProvider;
import com.jayway.jsonpath.spi.mapper.JsonOrgMappingProvider;

public class JsonPathThrowsNullPointer {
		
	public static void main(String[] args) {
		String json = "{\"foo\": \"bar\", \"emptyObject\": {}}";

		Configuration config = Configuration.defaultConfiguration()
				.jsonProvider(new JsonOrgJsonProvider())
				.mappingProvider(new JsonOrgMappingProvider());
		
		Object result = JsonPath.using(config).parse(json).read("$..foo");
		System.out.println(result);
	}
	
}

Using:

<dependency>
  <groupId>com.jayway.jsonpath</groupId>
  <artifactId>json-path</artifactId>
  <version>2.3.0</version>
</dependency>

Exception stack trace:

Exception in thread "main" java.lang.NullPointerException at com.jayway.jsonpath.spi.json.JsonOrgJsonProvider.getPropertyKeys(JsonOrgJsonProvider.java:155) at com.jayway.jsonpath.internal.path.ScanPathToken$PropertyPathTokenPredicate.matches(ScanPathToken.java:202) at com.jayway.jsonpath.internal.path.ScanPathToken.walkObject(ScanPathToken.java:75) at com.jayway.jsonpath.internal.path.ScanPathToken.walk(ScanPathToken.java:41) at com.jayway.jsonpath.internal.path.ScanPathToken.walkObject(ScanPathToken.java:84) at com.jayway.jsonpath.internal.path.ScanPathToken.walk(ScanPathToken.java:41) at com.jayway.jsonpath.internal.path.ScanPathToken.evaluate(ScanPathToken.java:36) at com.jayway.jsonpath.internal.path.RootPathToken.evaluate(RootPathToken.java:62) at com.jayway.jsonpath.internal.path.CompiledPath.evaluate(CompiledPath.java:53) at com.jayway.jsonpath.internal.path.CompiledPath.evaluate(CompiledPath.java:61) at com.jayway.jsonpath.JsonPath.read(JsonPath.java:187) at com.jayway.jsonpath.internal.JsonContext.read(JsonContext.java:102) at com.jayway.jsonpath.internal.JsonContext.read(JsonContext.java:89) at JsonPathThrowsNullPointer.main(JsonPathThrowsNullPointer.java:17)

kallestenflo pushed a commit that referenced this issue Jun 2, 2021
* The method getPropertyKeys() in class JsonOrgJsonProvider doesn't check empty jsonObject.

* Addition testcase

* simplify the implementation. And change method names of testcases to something more descriptive

* change names
@kallestenflo
Copy link
Contributor

Fixed by #699

fbacchella added a commit to fbacchella/jrds that referenced this issue Nov 15, 2021
is not needed any more in jrds-jsonp.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants